🔒
Auth2M+/wkMIT

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
npm install express-rate-limit
yarn
yarn add express-rate-limit
pnpm
pnpm add express-rate-limit

Import

ESM
import rateLimit from 'express-rate-limit';

Quick Example

usage
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

Packageexpress-rate-limit
CategoryAuth
Weekly Downloads2M+
LicenseMIT
Installnpm install express-rate-limit

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.