ratelimiter-middleware
v2.0.4
Published
Abstract RateLimiter which uses Redis
Downloads
6
Maintainers
Readme
ratelimiter-middleware
Basic rate-limiting middleware for Express. Used to limit repeated requests to public APIs and/or endpoints. It can be used to rateLimit a specific appId
(specified in the request headers) and by default it rateLimits IP addresses.
Ensure that your redis server is running before using
Installation
npm i --save ratelimiter-middleware
Usage
const express = require('express');
const app = express();
const rateLimiter = require('ratelimiter-middleware');
const maxRequests = 100;
const timeLimit = 60; // seconds
const appId = 'appId'; // The request header that you specify
app.use(rateLimiter(maxRequests,timeLimit, appId));
// The appId parameter can be left empty if you want to rateLimit based
// on IP address
// eg. app.use(rateLimiter(maxRequests,timeLimit));
app.get('/', (req, res) => {
res.json({ msg: 'AoK' });
});