node-fetch-retry is a lightweight wrapper library designed to enhance `node-fetch` with automatic retry capabilities. It enables developers to specify a fixed number of retry attempts for network requests, introduce a pause duration between retries, and execute a custom callback function before each attempt. The current stable version is 2.0.1. Its release cadence appears to be infrequent, with the last notable activity several years ago, suggesting it is in maintenance mode or effectively abandoned. This library differentiates itself by offering a straightforward, integrated retry mechanism directly within the `fetch` options, making it a simple choice for adding basic request resilience without complex configurations often found in more feature-rich alternatives. It's best suited for Node.js environments requiring basic retry logic for transient network failures.
npm install node-fetch-retryVerified import paths — ran on the pinned version, not inferred.
Demonstrates fetching a URL with a specified number of retries and a pause between attempts, including a callback to log each retry attempt.
If encountering `ERR_REQUIRE_ESM`, ensure your project and `node-fetch-retry` are compatible with `node-fetch@2`. Alternatively, rewrite your application to use ESM and consider `node-fetch` directly with custom retry logic or an ESM-compatible retry wrapper.
Assess the library's stability and feature set against your needs. For actively maintained alternatives with more advanced retry features (e.g., exponential backoff, retry on specific status codes), consider libraries like `fetch-retry` or `@adobe/node-fetch-retry`.
Only use retry logic for idempotent methods like GET, PUT, and DELETE where repeating a request has no additional side effects. For non-idempotent requests, implement transactional logic or unique request IDs to ensure operations are only performed once.
For complex retry scenarios, consider libraries like `fetch-retry` which offer configurable `retryDelay` functions (for exponential backoff) and `retryOn` options for specific status codes.
Either convert your project or the specific file to CommonJS (`.js` extension without `"type": "module"`) or use dynamic `import()` if `node-fetch-retry` supports it, or use an alternative library designed for ESM.
Ensure `node-fetch-retry` is correctly installed (`npm install node-fetch-retry`) and that the `require` statement is at the top level of your CommonJS module. Verify `node-fetch` is a compatible version with `node-fetch-retry` (likely `node-fetch@2`).
Downgrade your direct or indirect `node-fetch` dependency to version 2 (e.g., `npm install node-fetch@2`) if `node-fetch-retry` doesn't explicitly state ESM compatibility. Alternatively, migrate your project to ESM if feasible, or use `import('node-fetch').then(...)` for dynamic loading if supported.