Skip to content

express-quota-limiter #492

@kfiross

Description

@kfiross

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions