ratelimiter-middleware

2.0.4 • Public • Published

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' });
});

Package Sidebar

Install

npm i ratelimiter-middleware

Weekly Downloads

2

Version

2.0.4

License

MIT

Unpacked Size

3.72 kB

Total Files

4

Last publish

Collaborators

  • kartikkhk