createQuotaLimiter. You pass it a storage driver, a function that derives a quota key from the request, and a limit. The middleware then counts usage against that key and responds with HTTP 429 when the quota is exhausted.
Installation
Peer dependencies
The package has zero mandatory runtime dependencies. Install a Redis client only if you plan to useRedisDriver:
MemoryDriver has no peer dependencies and works out of the box.
Setup
1
Install the package
Run one of the install commands above. The package ships with TypeScript types — no separate
@types/ package is needed.2
Choose a driver
Pick the storage driver that fits your environment:
RedisDriver— for production and staging. Compatible with bothioredisandnode-redisv4. Uses a MULTI/EXEC pipeline to atomically initialise and decrement the counter with no race conditions.MemoryDriver— for local development and unit tests. No external dependencies. Not suitable for multi-process deployments because each process maintains its own isolated store.
3
Create the middleware
Call
createQuotaLimiter with your driver and options. The keyGenerator function receives the Express Request object and must return a string that uniquely identifies the quota bucket — for example, a tenant ID or user ID.4
Attach to an Express route
Pass the middleware directly to any Express route or router:When the quota is exhausted the middleware responds with Every response — allowed or blocked — also receives two headers:
HTTP 429 before your handler runs:Complete example
The following is a working TypeScript example that combines all four steps:Next steps
Quota keys
Learn how to design keys for per-tenant, per-user, and per-route quotas.
Multi-tenant guide
Enforce different limits per tenant plan with dynamic
limit resolution.createQuotaLimiter reference
Full reference for all options including callbacks and request weighting.