Express Limiter is a middleware for Express applications designed to enforce rate limiting on incoming HTTP requests, built specifically on Redis. It allows developers to configure limits based on various request properties like IP address, user ID, or custom functions. The package provides granular control over rate limiting rules, including total requests, expiration times, whitelisting, and custom handling for rate-limited requests. This package is currently at version 1.6.1, with its last update on npm in September 2017. Due to its age and lack of recent updates, it is largely considered unmaintained, with more modern and actively developed alternatives like `express-rate-limit` being preferred for new projects. It differentiates itself by being tightly coupled with Redis for distributed rate limiting.
npm install express-limiterVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing `express-limiter` with an Express app and Redis client, then applying a basic rate limit to a specific route.
Migrate to `express-rate-limit` (npmjs.com/package/express-rate-limit) for active maintenance, security updates, and ESM support.
Ensure a Redis server is running and accessible. Configure the `redis` client correctly before passing it to `express-limiter`. Implement error handling for the Redis client connection.
Configure the `lookup` option to use `headers.x-forwarded-for` (or similar proxy-specific header) and ensure your Express app's `trust proxy` setting is correctly configured (`app.set('trust proxy', true)` or a specific IP/subnet).Set `ignoreErrors: true` if you want requests to proceed on Redis errors (e.g., for graceful degradation). Use the `onRateLimited` option to provide custom error responses (e.g., JSON error objects with status 429) instead of the default behavior.
Start your Redis server (e.g., `redis-server`) and verify its configuration. Ensure your application's Redis client is configured with the correct host and port.
Call the `require('express-limiter')` result with your Express app/router and a Redis client: `const limiter = require('express-limiter')(app, client);`Set `app.set('trust proxy', true)` in your Express application and configure `lookup: 'headers.x-forwarded-for'` in your `limiter` options. Adjust `trust proxy` to a specific IP or subnet if known for better security.