Framework-agnostic rate limiting library with sliding window algorithm
npm install @jfungus/ratelimit


Framework-agnostic rate limiting library with sliding window algorithm. Zero dependencies.
``bash`
npm install @jfungus/ratelimit
`ts
import { RateLimiter, MemoryStore } from "@jfungus/ratelimit";
const store = new MemoryStore();
store.init(60 * 1000); // 1 minute window
const limiter = new RateLimiter({
limit: 100,
windowMs: 60 * 1000, // 1 minute
store,
});
// Check rate limit
const result = await limiter.check("user-123");
if (!result.allowed) {
console.log(Rate limited. Retry after ${result.retryAfter}ms);`
}
Cloudflare-style weighted sliding window for smoother rate limiting:
`ts`
const limiter = new RateLimiter({
algorithm: "sliding-window",
limit: 100,
windowMs: 60 * 1000, // 1 minute
store,
});
Simple counter that resets at fixed intervals:
`ts`
const limiter = new RateLimiter({
algorithm: "fixed-window",
limit: 100,
windowMs: 60 * 1000, // 1 minute
store,
});
For framework-specific middleware, see:
- @jfungus/ratelimit-hono - Hono
- @jfungus/ratelimit-express - Express
- @jfungus/ratelimit-h3 - H3/Nitro
- @jfungus/ratelimit-nuxt` - Nuxt
MIT