universal-rate-limit
Web-standards-based rate limiting with pluggable stores and framework middleware. Zero dependencies, works everywhere.

Try the playground to configure limits, fire requests, and see rate limiting in action — right in your browser.
Quick Start
Installation
npm install universal-rate-limitUsage
import { rateLimit } from 'universal-rate-limit';
const limiter = rateLimit({
algorithm: { type: 'sliding-window', windowMs: 60_000 }, // 1 minute
limit: 60 // 60 requests per window
});
const result = await limiter(request);
if (result.limited) {
return new Response('Too Many Requests', {
status: 429,
headers: result.headers
});
}Middleware
Rate limit any framework with a single line:
Express
import { expressRateLimit } from '@universal-rate-limit/express';
app.use(expressRateLimit({ algorithm: { type: 'sliding-window', windowMs: 60_000 }, limit: 60 }));Hono
import { honoRateLimit } from '@universal-rate-limit/hono';
app.use(honoRateLimit({ algorithm: { type: 'sliding-window', windowMs: 60_000 }, limit: 60 }));Redis Store
Scale across multiple instances with the official Redis store:
import { rateLimit } from 'universal-rate-limit';
import { RedisStore } from '@universal-rate-limit/redis';
const limiter = rateLimit({
algorithm: { type: 'sliding-window', windowMs: 60_000 },
limit: 60,
store: new RedisStore({
sendCommand: (...args) => redis.call(...args)
})
});Packages
| Package | Description |
|---|---|
universal-rate-limit | Core rate limiting library |
@universal-rate-limit/redis | Redis store |
@universal-rate-limit/express | Express middleware |
@universal-rate-limit/fastify | Fastify plugin |
@universal-rate-limit/hono | Hono middleware |
@universal-rate-limit/nextjs | Next.js App Router wrapper |
Acknowledgements
Inspired by express-rate-limit — the most popular rate limiting middleware for Express.js. universal-rate-limit builds on its proven API design while extending it to work across frameworks and runtimes with Web Standard APIs.