Rate limiter for Node.js backed by Redis.
NOTE: Promise version available at async-ratelimiter.
v2.0.0 - API CHANGE - Change
remaining to include current call instead of decreasing it. Decreasing caused an off-by-one problem and caller could not distinguish between last legit call and a rejected call.
- Redis 2.6.12+
- Node 6.0.0+
$ npm install ratelimiter
Example Connect middleware implementation limiting against a
var id = requser_id;var limit = id: id db: db ;limit;
remaining- number of calls left in current
durationwithout decreasing current
reset- time since epoch in seconds at which the rate limiting period will end (or already ended)
resetMs- time since epoch in milliseconds at which the rate limiting period will end (or already ended)
id- the identifier to limit against (typically a user id)
db- redis connection instance
max- max requests within
duration- of limit in milliseconds