retry-axios is a library designed to automatically retry failed HTTP requests made using the Axios client library. It operates as an Axios interceptor, providing built-in exponential backoff and extensive configuration options for retry logic, including HTTP methods, status codes, retry delays, and jitter strategies. The current stable version is 4.0.3, released in April 2026. The package demonstrates a consistent release cadence, with major versions aligning with significant Node.js LTS updates. Key differentiators include its deep integration with Axios interceptors, allowing for global or instance-specific retry policies, and its flexible backoff algorithms (exponential, static, linear) to prevent thundering herd problems, making it suitable for robust client-side network operations in both Node.js and browser environments.
npm install retry-axiosVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a custom Axios instance, configure `retry-axios` for it with specific retry policies (count, delay, status codes, backoff, jitter), and attach the retry interceptor. It includes an `onError` callback for logging and illustrates fetching data from an endpoint that might return a retryable status code, showcasing the retry mechanism in action.
Upgrade your Node.js runtime to version 20 or newer. If you must use an older Node.js version, you will need to stick with `retry-axios` v3.x.
Always use `import * as rax from 'retry-axios';` for ESM imports. For CommonJS, `const rax = require('retry-axios');` is correct.Use `rax.attach()` for global attachment. For scoped behavior, create an Axios instance (`const myAxios = axios.create();`) and then call `rax.attach(myAxios);`.
Update your configuration to use the `raxConfig` property within `axios.defaults` or `axiosInstance.defaults`, e.g., `myAxiosInstance.defaults.raxConfig = {...};`.Change `import rax from 'retry-axios';` to `import * as rax from 'retry-axios';`.
Ensure the target URL is correct and reachable. If it's an intermittent issue, `retry-axios` with its default configuration will attempt to retry, potentially resolving the issue on subsequent attempts. Check DNS settings and network connectivity.
This error itself is expected to be caught and retried by `retry-axios`. If retries are not happening, verify that `rax.attach()` was called and that `raxConfig.statusCodesToRetry` includes the relevant 5xx range. Increase `raxConfig.retry` if more attempts are needed.