Express middleware for IP-based rate limiting with flexible configuration options and multiple storage backends
Overall
score
96%
Build an Express middleware that enforces per-request limits based on asynchronously resolved client plans. Plans are determined at request time and control how many calls are allowed before returning a 429 response with a plan-aware payload.
X-Plan: pro may perform 6 actions within a 60s window, while requests without that header default to 2. The third basic request in the window returns HTTP 429, but a pro request is still accepted until the seventh call triggers 429. @testX-User header and the request path. Requests from the same user on two different paths should not share a counter; each path allows its own quota before 429. @test{ plan, reason, retryAfterSeconds }. The plan value reflects the resolved plan name, and retryAfterSeconds reflects the remaining window rounded up. @testX-Limit-Source: fallback on all responses. @test@generates
import type { Request, RequestHandler } from "express";
export interface PlanInfo {
name: string;
windowMs: number;
limit: number;
blockMessage?: string;
}
export interface PlanLimiterOptions {
fetchPlan: (req: Request) => Promise<PlanInfo | null>;
defaultPlan: PlanInfo;
}
export function createPlanAwareLimiter(options: PlanLimiterOptions): RequestHandler;Express middleware that enforces request quotas with support for asynchronous option resolvers. @satisfied-by
HTTP framework providing request/response types and middleware composition. @satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-express-rate-limitevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10