1.Please make sure you have Node.js installed on your development environment.
2.Please make sure you have a Redis server installed on your development environment or make sure you initialize the Redis client with appropriate host and port number later on when you run the application.
3.Once you clone this repository, run npm install on your command line to get all the dependencies.
1.require module var ratelimiter = require('ratelimiter');
-
Create Rate limit configurations
var limitsConfig = { ECOM : {total: {week:[100, 604800], month:[600, 2628000], hour: [500, 3600], min:[20, 60]}, GET: { min: [20, 604800] }, '/status':{min: [20 ,60]} }, ABC : {total: {week:[10, 604800], hour:[5, 3600], min: [5, 60] }, POST: { week:[ 20, 604800 ]}, '/pay':{min:[ 30, 60] } } }
-
Create redis instance
var REDIS_PORT = 6379; var REDIS_HOST = "127.0.0.1"; var redisClient = redis.createClient(REDIS_PORT, REDIS_HOST);
-
Finally pass the rate limits config and redisClient to rate limit middleware
app.use(ratelimiter(limitsConfig, redisClient));
ii) Redis supports partioning.
iii) There can be different instances of the RateLimiter object running, but they will all have access to the same traffic info via Redis.