express-quota-limiter #7198
kfiross
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Just wanted to share I created express-quota-limiter
express-quota-limiter is a flexible, TypeScript-based middleware for Express.js designed specifically for managing long-term quotas (e.g., monthly email limits or daily API allowances) rather than short-term rate limiting.
Core Overview
Purpose: Tracks and enforces usage limits over long windows (days, weeks, months).
Backend Agnostic: Uses a driver-based system. It supports Redis (via ioredis or node-redis) for production and a MemoryDriver for local testing.
Atomic Operations: Prevents race conditions using Redis pipelines, ensuring accurate counting even with concurrent requests.
Key Features
Custom Key Generation: Define how to identify users or tenants (e.g., by User ID, API Key, or IP).
Request Weighting: Assign different "costs" to different requests. For example, a single bulk-upload request can consume 50 units of a quota, while a single fetch consumes only 1.
Dynamic Limits: Supports fetching limits asynchronously (e.g., pulling a user's specific plan limit from a database during the request).
Fail-Open Design: If the storage backend (like Redis) goes down, the middleware allows requests through by default to avoid breaking the application.
Callbacks: Includes hooks like onQuotaChecked and onQuotaExceeded for logging, analytics, or triggering billing alerts.
Beta Was this translation helpful? Give feedback.
All reactions