Registry / http-networking / requestretry

requestretry

JSON →
library8.0.0jsnpmunverified

request-retry is a Node.js library designed to automatically re-attempt HTTP(S) requests that fail due to transient network errors or specific HTTP status codes like 5xx and 429 (Too Many Requests). It functions as a wrapper, providing a drop-in replacement API for the underlying HTTP client, but with added configurable retry logic including `maxAttempts`, `retryDelay`, and a customizable `retryStrategy`. The current stable version, 8.0.0, marks a significant shift, migrating its core dependency from the unmaintained `request` library to the more actively developed `postman-request` fork, addressing security concerns and ensuring continued functionality. This package is crucial for building robust network clients that can gracefully handle temporary service disruptions, simplifying the implementation of resilient communication patterns by abstracting away common retry mechanisms.

npm install requestretry
INSTALL
IMPORT
SIG · REQUESTRETRY
R
requestretry
http-networkingjavascriptv8.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

request
const request = require('requestretry');
import request from 'requestretry';
Primarily designed for CommonJS. For ESM, direct `import` requires a build step or Node.js's CJS interoperability.
RetryStrategies
const request = require('requestretry'); const strategy = request.RetryStrategies.HTTPOrNetworkError;
import { RetryStrategies } from 'requestretry';
RetryStrategies is an enumerable property on the main 'requestretry' export, not a separate named export.
request (Promise-based usage)
const request = require('requestretry'); request({ /* options */ }).then(/* ... */);
import requestPromise from 'requestretry/promise';
Promise support is built into the main 'requestretry' export; no separate promise-specific import is needed.

Demonstrates a basic promise-based HTTP GET request using request-retry, configured to retry on 5xx errors or network issues with a delay.

// First, ensure you have the necessary peer dependency installed: // npm install requestretry postman-request const request = require('requestretry'); async function makeRetriedRequest() { console.log('Initiating retriable HTTP request...'); try { const response = await request({ url: 'https://httpstat.us/503', // An endpoint that reliably returns a 503 (Service Unavailable) json: true, // Parse response body as JSON maxAttempts: 3, // Configure up to 3 attempts retryDelay: 1000, // Wait 1 second between retries retryStrategy: request.RetryStrategies.HTTPOrNetworkError, // Retry on 5xx status codes or network errors fullResponse: true // Resolve the promise with the full response object, including headers and status }); console.log(`\nRequest successfully completed after ${response.attempts} attempts.`); console.log(`HTTP Status Code: ${response.statusCode}`); console.log(`Response Body: ${JSON.stringify(response.body, null, 2)}`); } catch (error) { console.error(`\nRequest failed after all attempts. Error: ${error.message}`); if (error.attempts) { console.error(`Total attempts made: ${error.attempts}`); } } } makeRetriedRequest();
Debug
Known issues
breakingVersion 8.0.0 replaced the deprecated `request` library with `postman-request`. This is a breaking change in its underlying dependency, though the API surface aims to remain compatible. Users must explicitly install `postman-request` as a peer dependency.
fix
Ensure `postman-request` is installed in your project: `npm install postman-request`
affects: >=8.0.0
gotchaThe original `request` library, on which older versions of `request-retry` were based, is deprecated and no longer maintained. While v8.0.0 migrates to `postman-request`, users should be aware that `postman-request` is a fork and may have subtle differences or its own future maintenance considerations.
fix
For new projects, consider modern alternatives to the `request` API if deep integration or long-term stability with the underlying HTTP client is critical, or rely on `postman-request`'s continued maintenance.
affects: >=1.0.0
gotcha`request-retry` expects `postman-request` as a peer dependency. If `postman-request` is not installed, the library will fail with a module not found error, as it cannot function without its underlying HTTP client.
fix
Install the peer dependency: `npm install postman-request`.
affects: >=8.0.0
Errors
Common errors & fixes
Error: Cannot find module 'postman-request'
The peer dependency 'postman-request' is not installed in the project.
fix
Run `npm install postman-request` to install the required HTTP client.
TypeError: request is not a function
Attempting to use `requestretry` with an ES module `import` statement in a CommonJS-only Node.js environment, or an incorrect import style.
fix
Use CommonJS `require` syntax: `const request = require('requestretry');` Ensure your project's module type is correctly configured if using ESM.
(node:xyz) DeprecationWarning: The request package has been deprecated.
This warning indicates that your project (or a transitive dependency) is still using an older version of `request-retry` (pre-v8.0.0) which relies on the deprecated `request` library.
fix
Upgrade `request-retry` to version 8.0.0 or higher: `npm install requestretry@latest`. Also, ensure `postman-request` is installed as a peer dependency.
Upgrade
Version history
8.0.0latest on npm
Audit
Dependencies
postman-requestrequiredCore HTTP client library wrapped by request-retry for its functionality. Required as a peer dependency since v8.0.0.
Agent activity
7 hits · last 30 days
node
6
Resources
requestretry — npm install requestretry · libregistry