A sliding window rate limiter supporting Redis >= 3.2 backend or in-memory backend. Current stable version 6.0.1 requires Node >= 16 and ES6. Provides check, reserve, and cancel operations with automatic cleanup. Key differentiators: supports both Redis and in-memory backends, includes safe mode with automatic reconnection, and uses a sliding window algorithm rather than fixed window. Actively maintained with frequent releases.
npm install sliding-window-rate-limiterNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows in-memory and Redis-backed rate limiter initialization, check, reserve, and cancel operations.
Upgrade Node.js to version 16.0.0 or higher.
Replace `limiter.usage(key, limit)` with `limiter.check(key, limit)`.
Use `SlidingWindowRateLimiter.createLimiter({ interval, redis, safe: true })` instead of instantiating SafeRedisBackend directly.Use `const { SlidingWindowRateLimiter } = require('sliding-window-rate-limiter')`.Pass an explicit `redis` instance with your own retry strategy rather than a URL string.
Set `operationTimeout: 0` if you need the old behavior of no timeout; otherwise adjust your code for 5s timeout.
Upgrade Redis server to version 3.2.0 or later.
In CommonJS: const { SlidingWindowRateLimiter } = require('sliding-window-rate-limiter'). In ESM: import { SlidingWindowRateLimiter } from 'sliding-window-rate-limiter'.Ensure Redis server is running and accessible. Consider setting a longer retryStrategy or increasing operationTimeout.
Use import { SlidingWindowRateLimiter } from 'sliding-window-rate-limiter' instead of require().