limitguard-elsolya
v0.1.0
Published
Distributed fixed-window, sliding-window, and token-bucket rate limiting
Maintainers
Readme
limitguard-elsolya
Distributed rate limiting with fixed-window, sliding-window, and token-bucket algorithms.
Install
npm install limitguard-elsolyaUsage
import { createRateLimiter, createMemoryRateLimitStore } from "limitguard-elsolya";
const limiter = createRateLimiter({
store: createMemoryRateLimitStore(),
algorithm: "sliding-window",
limit: 100,
window: "1m",
key: (ctx) => ctx.userId ?? ctx.ip ?? "anonymous",
});
const [result] = await limiter.consume({ userId: "user_1", ip: "127.0.0.1" });Stores
- Memory —
createMemoryRateLimitStore() - Redis —
createRedisRateLimitStore({ client }) - PostgreSQL —
createPostgresRateLimitStore({ client })+POSTGRES_MIGRATION
License
MIT
