RedisDriver in production for atomic, race-condition-free counting across multiple servers, and swap in the built-in MemoryDriver for tests with no infrastructure required.
Key features
Driver-based storage
Use the included
RedisDriver or MemoryDriver, or implement the QuotaStorage interface to plug in any backend.Atomic operations
The Redis driver uses a MULTI/EXEC pipeline (SET NX + DECRBY) to prevent race conditions without Lua scripts.
Custom quota keys
Derive any key from the request — per-tenant, per-user, per-route, or any combination — with a
keyGenerator function.Request weighting
Charge different amounts per request using
quotaWeight. A bulk send of 50 emails can consume 50 quota units in one request.Dynamic limits
Resolve limits at request time with an async
limit function — ideal for multi-tenant apps where each plan has a different cap.Fire-and-forget callbacks
Hook into every check (
onQuotaChecked) or only blocked requests (onQuotaExceeded) without affecting response time.Fail-open by default
Storage errors never block your users. Set
failOpen: false if you need strict enforcement even during outages.TypeScript-first
Full types are bundled — no separate
@types/ package needed.When to use it
express-quota-limiter is the right tool when your limits are measured in windows longer than a minute:- Monthly email sending — cap each tenant at 500 emails per month
- Daily API call budgets — enforce a 1,000-call-per-day limit for free-tier users
- Bulk action quotas — charge a weight of N for requests that perform N operations (e.g. sending N emails at once)
- Per-plan feature limits — give Pro tenants 10,000 calls and Free tenants 500, resolved dynamically per request
- Credit-based systems — deduct credits on each request and block when the balance reaches zero
If you need to prevent traffic spikes over seconds or minutes (e.g. 100 requests per minute), a traditional rate limiter like
express-rate-limit is a better fit. express-quota-limiter is designed for long-window business-logic limits, not burst protection.Quota limiter vs rate limiter
Both quota limiters and rate limiters count requests and block when a threshold is crossed, but they serve different purposes:
express-quota-limiter is optimised for the right-hand column. It uses a TTL-based counter that starts counting when the first request arrives in a window, and expires automatically when the TTL elapses.
Next steps
Get started with express-quota-limiter
Install the package and add your first quota middleware in under five minutes.