express-rate-limiter is a middleware for Express.js applications designed to control and limit incoming requests based on user IP addresses. It implements a dual-tier rate limiting strategy: an 'inner limit' to prevent rapid-fire requests (hammering) and an 'outer limit' to guard against general overuse. The current stable version is 1.3.1. While the package previously removed external dependencies for its storage mechanism, it now primarily utilizes an in-memory store, with a roadmap item to support pluggable database solutions like Redis. Key differentiators include its configurable dual-limit approach and automatic inclusion of standard X-RateLimit and Retry-After HTTP headers in responses when limits are exceeded. Releases appear somewhat irregular but indicate active maintenance through minor versions.
npm install express-rate-limiterVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `express-rate-limiter` with its default `MemoryStore`, applying rate limiting to both specific routes and globally in an Express application, including custom settings per middleware.
Review the `lib/store.js` interface and adapt any custom database implementations. Ensure `new Limiter({ db: new MemoryStore() })` or a custom store adhering to the new interface is passed during initialization.Always initialize `Limiter` with a database store, for example: `new Limiter({ db : new MemoryStore() })`.Clients should re-validate their handling of the `Retry-After` header to ensure it correctly interprets the HTTP-compliant value.
If `pathLimiter: true`, ensure a consistent `path` is provided either globally or per middleware, or understand that limits will be distinct for each unique request path segment.
Ensure `var limiter = new Limiter({ db : new MemoryStore() });` is executed before `app.use(limiter.middleware());` or similar calls.Initialize the limiter with a database store, typically `new Limiter({ db: new MemoryStore() });` or your custom store implementation.For ESM, use `import Limiter from 'express-rate-limiter';`. For CommonJS in Node.js, use `const Limiter = require('express-rate-limiter');`.No dependency data recorded yet.