Throttle HTTP Requests with `request`

0.1.1 · abandoned · verified Wed Apr 22

throttled-request is a Node.js module designed to apply rate-limiting to outgoing HTTP requests by wrapping the now-deprecated `request` library. It provides functionality to configure request throttling based on a fixed rate (e.g., N requests within M milliseconds) or a dynamic delay determined by a provided function. The package is currently at version 0.1.1, indicating an early development stage and a lack of active maintenance. Its release cadence is effectively inactive, as its last update was long ago, and its core dependency, `request`, has been officially deprecated and archived. This module's primary differentiator was its simple integration with the `request` API, making it easy for users of that library to add throttling. However, its strong reliance on an unmaintained dependency makes it unsuitable for modern applications, which should seek alternatives built on actively maintained HTTP clients.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to set up `throttled-request`, configure a rate limit of 2 requests per second, listen for the 'request' event, and then make 10 throttled HTTP GET requests to a public URL.

var request = require('request')
,   throttledRequest = require('throttled-request')(request)
,   startedAt = Date.now();

throttledRequest.configure({
  requests: 2,
  milliseconds: 1000
});

throttledRequest.on('request', function () {
  console.log('Making a request. Elapsed time: %d ms', Date.now() - startedAt);
});

//Throttle 10 requests in parallel to 'https://www.google.com/'
// Replace 'https://www.google.com/' with a safe, public URL for testing.
// In a real application, handle errors and ensure proper resource cleanup.
for (var i = 0; i < 10; i++) {
  throttledRequest('https://www.google.com/', function (error, response, body) {
    if (error) {
      console.error('Request failed:', error.message);
      return;
    }
    console.log('Got response for request %d. Status: %d. Elapsed time: %d ms', i, response.statusCode, Date.now() - startedAt);
  });
}

view raw JSON →