
Security News
/Research
Fake Corepack Site Distributes Infostealer and Proxyware to Developers
A fake corepack.org site is impersonating the Node.js tool and delivers an infostealer and proxyware to developers who download it.
retry-request
Advanced tools
THIS REPOSITORY AND PACKAGE WILL BE DEPRECATED IN JULY 2024. RELEVANT FUNCTIONALITIES HAVE BEEN MOVED TO GOOGLEAPIS/GAXIOS
![]() |
|---|
| Retry a request with built-in exponential backoff. |
$ npm install --save teeny-request
$ npm install --save retry-request
var request = require('retry-request', {
request: require('teeny-request'),
});
It should work the same as request and teeny-request in both callback mode and stream mode.
Note: This module only works when used as a readable stream, i.e. POST requests aren't supported (#3).
request?Yes! You must independently install teeny-request OR request (deprecated) and provide it to this library:
var request = require('retry-request', {
request: require('teeny-request'),
});
urlThatReturns503 will be requested 3 total times before giving up and executing the callback.
request(urlThatReturns503, function (err, resp, body) {});
urlThatReturns503 will be requested 3 total times before giving up and emitting the response and complete event as usual.
request(urlThatReturns503)
.on('error', function () {})
.on('response', function () {})
.on('complete', function () {});
Yes! To enable the debug mode, set the environment variable DEBUG to retry-request.
(Thanks for the implementation, @yihaozhadan!)
Passed directly to request or teeny-request. See the list of options supported:
opts.noResponseRetriesType: Number
Default: 2
The number of times to retry after a response fails to come through, such as a DNS resolution error or a socket hangup.
var opts = {
noResponseRetries: 0,
};
request(url, opts, function (err, resp, body) {
// url was requested 1 time before giving up and
// executing this callback.
});
opts.objectModeType: Boolean
Default: false
Set to true if your custom opts.request function returns a stream in object mode.
opts.retriesType: Number
Default: 2
var opts = {
retries: 4,
};
request(urlThatReturns503, opts, function (err, resp, body) {
// urlThatReturns503 was requested a total of 5 times
// before giving up and executing this callback.
});
opts.currentRetryAttemptType: Number
Default: 0
var opts = {
currentRetryAttempt: 1,
};
request(urlThatReturns503, opts, function (err, resp, body) {
// urlThatReturns503 was requested as if it already failed once.
});
opts.shouldRetryFnType: Function
Default: Returns true if http.incomingMessage.statusCode is < 200 or >= 400.
var opts = {
shouldRetryFn: function (incomingHttpMessage) {
return incomingHttpMessage.statusMessage !== 'OK';
},
};
request(urlThatReturnsNonOKStatusMessage, opts, function (err, resp, body) {
// urlThatReturnsNonOKStatusMessage was requested a
// total of 3 times, each time using `opts.shouldRetryFn`
// to decide if it should continue before giving up and
// executing this callback.
});
opts.requestType: Function
If we not provided we will throw an error advising you to provide it.
NOTE: If you override the request function, and it returns a stream in object mode, be sure to set opts.objectMode to true.
var originalRequest = require('teeny-request').defaults({
pool: {
maxSockets: Infinity,
},
});
var opts = {
request: originalRequest,
};
request(urlThatReturns503, opts, function (err, resp, body) {
// Your provided `originalRequest` instance was used.
});
opts.maxRetryDelayType: Number
Default: 64
The maximum time to delay in seconds. If retryDelayMultiplier results in a delay greater than maxRetryDelay, retries should delay by maxRetryDelay seconds instead.
opts.retryDelayMultiplierType: Number
Default: 2
The multiplier by which to increase the delay time between the completion of failed requests, and the initiation of the subsequent retrying request.
opts.totalTimeoutType: Number
Default: 600
The length of time to keep retrying in seconds. The last sleep period will be shortened as necessary, so that the last retry runs at deadline (and not considerably beyond it). The total time starting from when the initial request is sent, after which an error will be returned, regardless of the retrying attempts made meanwhile.
Passed directly to request. See the callback section: https://github.com/request/request/#requestoptions-callback.
axios-retry is a package that adds retry functionality to Axios requests. It is similar to retry-request but is specifically designed for use with Axios, a promise-based HTTP client, offering more modern syntax and promise support compared to the callback-based retry-request.
got is a more comprehensive HTTP request library that includes built-in retry functionality among many other features. Unlike retry-request, which is a wrapper around the request library, got is a standalone library offering a wide range of HTTP capabilities, including retries, which makes it a more versatile choice for complex applications.
superagent-retry extends the superagent library with retry capabilities. It is similar to retry-request in that it adds retry functionality to an existing HTTP request library, but it is tailored for superagent users. This package is a good choice for those already using superagent and looking to add simple retry mechanisms.
FAQs
Retry a request.
The npm package retry-request receives a total of 22,699,275 weekly downloads. As such, retry-request popularity was classified as popular.
We found that retry-request demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
A fake corepack.org site is impersonating the Node.js tool and delivers an infostealer and proxyware to developers who download it.

Research
/Security News
A large-scale campaign abused GitHub Actions in compromised repositories to exploit CVE-2026-41940 in cPanel and WHM and steal server credentials.

Security News
Five frontier LLMs generated the same nonexistent package names, leaving 53 available for potential slopsquatting across PyPI and npm.