A production-ready, open-source rate limiting library for Node.js and Next.js, built with TypeScript. v2.6.0 supports multiple algorithms (fixed window, sliding window, token bucket) via efficient Redis and Lua scripts. Features an optional registry system for managing multiple limiter configurations, ephemeral in-memory cache for resilience, configurable fail-open/closed strategies, analytics, and blocking support. Distributed under MIT license, actively maintained with regular releases.
npm install oss-ratelimitNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage creating a sliding window rate limiter with one Redis client, then calling limit() on an identifier.
Use dynamic import: const { Ratelimit } = await import('oss-ratelimit'); or switch your project to ESM.Replace 'regions' config with a single Redis client using 'getRedisClient'.
Update imports: use 'initRateLimit' from 'oss-ratelimit' and adjust usage per registry documentation.
Install redis@^4.0.0: npm install redis@^4.0.0
If using ephemeral cache, ensure limiter is slidingWindow(); otherwise set ephemeralCache: false.
Always use a non-empty string as the identifier.
Use dynamic import: const { Ratelimit } = await import('oss-ratelimit'); or convert project to ESM.Ensure initRateLimit is called and returns the Registry object with .limiter method.
Check Redis configuration; set 'stop-writes-on-bgsave-error no' in development or free disk space.
Start Redis server: redis-server, or set REDIS_URL env variable to a valid endpoint.