express-rate-limit
express-rate-limit is a basic rate-limiting middleware for Express that limits repeated requests to public APIs and endpoints. The middleware tracks the number …
Installation
npm install express-rate-limit
yarn add express-rate-limit
pnpm add express-rate-limit
Import
import rateLimit from 'express-rate-limit';
Quick Example
import express from 'express';
import rateLimit from 'express-rate-limit';
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit per window per IP
standardHeaders: true,
});
const app = express();
app.use('/api/', limiter);About express-rate-limit
express-rate-limit is a basic rate-limiting middleware for Express that limits repeated requests to public APIs and endpoints. The middleware tracks the number of requests from each client (identified by IP address by default) within a configurable time window and returns a 429 Too Many Requests response when the limit is exceeded. Rate limiting is essential for protecting APIs from abuse, brute-force attacks, denial-of-service attempts, and preventing excessive resource consumption. The middleware is configurable with windowMs (time window in milliseconds), max (maximum requests per window), message (custom response for rate-limited requests), standardHeaders (RateLimit-* response headers), and keyGenerator (custom client identification logic). By default, express-rate-limit uses an in-memory store that tracks request counts per IP, but for multi-instance deployments, external stores like rate-limit-redis, rate-limit-memcached, or rate-limit-mongo provide shared rate limiting across application instances. The middleware can be applied globally to all routes or selectively to specific endpoints like login or API routes. express-rate-limit is often used alongside helmet and cors as part of a standard Express security middleware stack.
Quick Facts
| Package | express-rate-limit |
| Category | Auth |
| Weekly Downloads | 2M+ |
| License | MIT |
| Install | npm install express-rate-limit |
Related Packages
Express is the most widely used web application framework for Node.js, providing a minimal and flexi…
Helmet helps secure Express.js applications by setting various HTTP response headers that protect ag…
CORS (Cross-Origin Resource Sharing) is an Express/Connect middleware that enables cross-origin requ…
hpp (HTTP Parameter Pollution) is an Express middleware that protects against HTTP Parameter Polluti…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.