multi-throttle

0.1.1 • Public • Published

Express throttling middleware

This middleware throttles the number of concurrent requests and the numbers of requests within in a given interval. Requests that exceed the limit of requests / interval are added to a queue and will be executed once current requests finish execution. If the number of queued requests exceeds the value for maxQueueSize, the requests will be dropped until an item is removed from the queue.

Installation

npm install -S multi-throttle

Usage

Add the middleware to your express app and adjust the configuration options.

import express from 'express';
import multiThrottle from 'multi-throttle';
 
const app = express();
app.use(multiThrottle({
  /**
   * The number of maximum allowed requests in the given interval
   */
  maxRequests: 10,
 
  /**
   * The interval within which the maxRequest limit is enforced in ms
   */
  interval: 1000,
 
  /**
   * Maximum number of concurrent running requests
   */
  maxConcurrency: 5,
 
  /**
   * Maximum number of queued requests before incoming requests are dropped
   */
  maxQueueSize: 10,
 
  /**
   * Optional: 
   * Function to send custom response object / status code when a request is dropped. 
   */
  handleError?: (req: express.Request, res: express.Response) => void
}));

Readme

Keywords

none

Package Sidebar

Install

npm i multi-throttle

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

70.3 kB

Total Files

14

Last publish

Collaborators

  • ivome