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 toreq.rateLimitResult:
Using IP as identifier
Using authenticated user ID
Automatic 429 Response
When the rate limit is exceeded, the middleware automatically responds with:TypeScript: Extending Request type
To avoid TypeScript errors when accessingreq.rateLimitResult, add a global type declaration: