node-rate-limiter
Simple calls rate limiter for Node.js®, inspired by @tj's node-ratelimiter
Package contains NodeRateLimiter that uses different adaptors for store rate's data to varios stores.
By default NodeRateLimiter supports local process memory, but you can also use following adaptors:
- node-rate-limiter-redis - adaptor for Redis database
Install
npm install node-rate-limiter
Usage
You can find default values under NodeRateLimiter namespace
NodeRateLimiterdefaults = rateLimit: 5000 // default number of call for current timeframe expiration: 3600000 // default duration in ms of current timeframe timeout: 500 // default timeout in ms of reset/get methods call ;
You can use default in memory store of current process just providing empty adaptor
const NodeRateLimiter = ;const nodeRateLimiter = ;
Or You can use one of the existing providers
const NodeRateLimiter = ;const SomeAdaptor = ; const nodeRateLimiter = /*...*/;
You can wrap your internal system module method
{ nodeRateLimiter;}
Or use it like middleware f.ex in Express
const NodeRateLimiter = ;const SomeAdaptor = ; const nodeRateLimiter = /*...*/; const express = ;const app = ; app;app;app; app; { nodeRateLimiter;}
If method call least too long, then callback will fires with Timeout error.
nodeRateLimiter;