{"id":17350,"library":"requestretry","title":"HTTP(S) Request Retry","description":"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.","status":"active","version":"8.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/FGRibreau/node-request-retry","tags":["javascript"],"install":[{"cmd":"npm install requestretry","lang":"bash","label":"npm"},{"cmd":"yarn add requestretry","lang":"bash","label":"yarn"},{"cmd":"pnpm add requestretry","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core HTTP client library wrapped by request-retry for its functionality. Required as a peer dependency since v8.0.0.","package":"postman-request","optional":false}],"imports":[{"note":"Primarily designed for CommonJS. For ESM, direct `import` requires a build step or Node.js's CJS interoperability.","wrong":"import request from 'requestretry';","symbol":"request","correct":"const request = require('requestretry');"},{"note":"RetryStrategies is an enumerable property on the main 'requestretry' export, not a separate named export.","wrong":"import { RetryStrategies } from 'requestretry';","symbol":"RetryStrategies","correct":"const request = require('requestretry');\nconst strategy = request.RetryStrategies.HTTPOrNetworkError;"},{"note":"Promise support is built into the main 'requestretry' export; no separate promise-specific import is needed.","wrong":"import requestPromise from 'requestretry/promise';","symbol":"request (Promise-based usage)","correct":"const request = require('requestretry');\nrequest({ /* options */ }).then(/* ... */);"}],"quickstart":{"code":"// First, ensure you have the necessary peer dependency installed:\n// npm install requestretry postman-request\n\nconst request = require('requestretry');\n\nasync function makeRetriedRequest() {\n  console.log('Initiating retriable HTTP request...');\n  try {\n    const response = await request({\n      url: 'https://httpstat.us/503', // An endpoint that reliably returns a 503 (Service Unavailable)\n      json: true, // Parse response body as JSON\n      maxAttempts: 3,   // Configure up to 3 attempts\n      retryDelay: 1000,  // Wait 1 second between retries\n      retryStrategy: request.RetryStrategies.HTTPOrNetworkError, // Retry on 5xx status codes or network errors\n      fullResponse: true // Resolve the promise with the full response object, including headers and status\n    });\n\n    console.log(`\\nRequest successfully completed after ${response.attempts} attempts.`);\n    console.log(`HTTP Status Code: ${response.statusCode}`);\n    console.log(`Response Body: ${JSON.stringify(response.body, null, 2)}`);\n  } catch (error) {\n    console.error(`\\nRequest failed after all attempts. Error: ${error.message}`);\n    if (error.attempts) {\n      console.error(`Total attempts made: ${error.attempts}`);\n    }\n  }\n}\n\nmakeRetriedRequest();","lang":"javascript","description":"Demonstrates a basic promise-based HTTP GET request using request-retry, configured to retry on 5xx errors or network issues with a delay."},"warnings":[{"fix":"Ensure `postman-request` is installed in your project: `npm install postman-request`","message":"Version 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.","severity":"breaking","affected_versions":">=8.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install the peer dependency: `npm install postman-request`.","message":"`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.","severity":"gotcha","affected_versions":">=8.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Run `npm install postman-request` to install the required HTTP client.","cause":"The peer dependency 'postman-request' is not installed in the project.","error":"Error: Cannot find module 'postman-request'"},{"fix":"Use CommonJS `require` syntax: `const request = require('requestretry');` Ensure your project's module type is correctly configured if using ESM.","cause":"Attempting to use `requestretry` with an ES module `import` statement in a CommonJS-only Node.js environment, or an incorrect import style.","error":"TypeError: request is not a function"},{"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.","cause":"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.","error":"(node:xyz) DeprecationWarning: The request package has been deprecated."}],"ecosystem":"npm","meta_description":null}