Projects /

Project overview

flex-rate-limit

A rate-limit decision engine with interchangeable counters for Node.js.

Use cases and boundaries

Use a single key policy for HTTP handlers and workers that share a quota. The core check returns the decision, remaining allowance and retry timing. Four algorithms cover fixed/sliding windows and token/leaky buckets. The host is responsible for choosing the key and mapping the decision to its own response.

Getting started and compatibility

Install the released package

npm install flex-rate-limit@2.2.5

Node.js 18+. Memory counters are local to one process. Multi-instance quotas need a shared Redis store or an explicitly configured cache-hub atomic backend. The example uses memory.

import { RateLimiter } from 'flex-rate-limit';
const limiter = new RateLimiter({ windowMs: 60_000, max: 12 });
const decision = await limiter.check('tenant:acme:exports');
console.log(decision.allowed, decision.remaining);

Project relationships