Skip to main content

Function: createRateLimiter()

createRateLimiter(__namedParameters): RateLimiter

Defined in: rateLimit.ts:31

A fixed-window counter per key, held in this process's memory.

In this process and no further: with N instances the effective limit is N times the configured one. That is the right trade for stopping a runaway client; a shared counter would put a store in the path of every request. A fixed window allows a burst of twice the limit at a boundary, for the same reason.

Expired keys are swept at most once a window, inside consume, so a key per IP does not grow memory without bound and no timer holds the process open.

Parameters​

ParameterTypeDescription
__namedParameters{ now?: () => number; windowMs: number; }-
__namedParameters.now?() => numberClock, for tests.
__namedParameters.windowMsnumber-

Returns​

RateLimiter