Skip to main content

Overview

RateLimitermiddleware wraps limiter.check() as an Express middleware so you don’t have to write the check/reject logic in every route handler.

Usage

Options

Accessing the Result in Your Handler

The middleware attaches the result to req.rateLimitResult:

Using IP as identifier

Using authenticated user ID

Automatic 429 Response

When the rate limit is exceeded, the middleware automatically responds with:
Your route handler is not called when the request is blocked.

TypeScript: Extending Request type

To avoid TypeScript errors when accessing req.rateLimitResult, add a global type declaration: