> ## Documentation Index
> Fetch the complete documentation index at: https://express-quota-limiter.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# express-quota-limiter: quota middleware for Express

> express-quota-limiter enforces long-window quotas in Express apps — monthly email limits, daily API budgets — with swappable Redis or in-memory storage.

express-quota-limiter is an Express.js middleware for enforcing long-window quotas. Where a standard rate limiter counts requests per second or per minute to prevent bursts, express-quota-limiter counts operations over days or months — think 500 emails per month, 1,000 API calls per day, or 50 bulk exports per billing cycle. The storage backend is fully swappable: use `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

> [card] Driver-based storage
>
> Use the included `RedisDriver` or `MemoryDriver`, or implement the `QuotaStorage` interface to plug in any backend.

> [card] Atomic operations
>
> The Redis driver uses a MULTI/EXEC pipeline (SET NX + DECRBY) to prevent race conditions without Lua scripts.

> [card] Custom quota keys
>
> Derive any key from the request — per-tenant, per-user, per-route, or any combination — with a `keyGenerator` function.

> [card] Request weighting
>
> Charge different amounts per request using `quotaWeight`. A bulk send of 50 emails can consume 50 quota units in one request.

> [card] Dynamic limits
>
> Resolve limits at request time with an async `limit` function — ideal for multi-tenant apps where each plan has a different cap.

> [card] Fire-and-forget callbacks
>
> Hook into every check (`onQuotaChecked`) or only blocked requests (`onQuotaExceeded`) without affecting response time.

> [card] Fail-open by default
>
> Storage errors never block your users. Set `failOpen: false` if you need strict enforcement even during outages.

> [card] 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

> [!NOTE]
>
> 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:

| | Rate limiter | Quota limiter |
| - | - | - |
| **Window length** | Seconds or minutes | Hours, days, or months |
| **Primary goal** | Prevent traffic bursts | Enforce business-logic caps |
| **Typical use case** | API abuse protection | Billing limits, plan enforcement |
| **Reset cadence** | Rolls or resets frequently | Resets on a billing or calendar cycle |
| **Storage concern** | High write throughput | Accuracy across long windows |

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

> [card] [Get started with express-quota-limiter](https://express-quota-limiter.mintlify.site/quickstart.md)
>
> Install the package and add your first quota middleware in under five minutes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.