Registry / devops / node-fetch-retry-timeout

node-fetch-retry-timeout

JSON →
library1.2.1jsnpmunverified

Minimalistic drop-in replacement for node-fetch with built-in retry and timeout support. Current version 1.2.1. It distinguishes itself from alternatives by configuring retries via attempt count (not total duration), supporting per-request timeouts via AbortController, and allowing dynamic option changes on each retry via beforeRetry callback. Offers flexible retry logic using a callback based on HTTP response status. Active maintenance.

npm install node-fetch-retry-timeout
INSTALL
IMPORT
SIG · NODE-FETCH-RETRY-T
N
node-fetch-retry-timeout
devopsjavascriptv1.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default (fetch)
const fetch = require('node-fetch-retry-timeout')
CommonJS default import. The module exports a single function that is a drop-in replacement for node-fetch.
default (fetch) via ESM
import fetch from 'node-fetch-retry-timeout'
const fetch = require('node-fetch-retry-timeout').default
ESM default import works directly; do not try to access .default with require.
TypeScript usage
import fetch from 'node-fetch-retry-timeout'
import { fetch } from 'node-fetch-retry-timeout'
The module does not ship TypeScript declarations; use @types/node-fetch for type information.

Basic usage with retry, timeout, and beforeRetry callback. Shows drop-in replacement for node-fetch with additional options.

const fetch = require('node-fetch-retry-timeout'); async function main() { // options are optional; defaults shown const response = await fetch('https://api.example.com/data', { method: 'GET', retry: 3, // number of retry attempts pause: 1000, // pause between retries in ms timeout: 10000, // per-request timeout in ms retryOnHttpResponse: r => r.status >= 500, beforeRetry: (retryNum, error) => { console.log(`Retry ${retryNum} after error: ${error}`); return {}; // return modified options if needed } }); console.log(await response.text()); } main().catch(console.error);
Debug
Known issues
breakingDefault redirect strategy is 'manual' (unlike node-fetch which defaults to 'follow')
fix
Explicitly set redirect: 'follow' in options if you need automatic redirect following.
affects: >=1.0.0
breakingDefault response timeout is 20 seconds
fix
Set timeout option to override (0 disables timeout).
affects: >=1.0.0
breakingRetry on HTTP 50x responses is enabled by default
fix
Pass retryOnHttpResponse: false to disable automatic retry on 5xx status codes.
affects: >=1.0.0
gotchabeforeRetry callback receives zero-based retryNum (0 before first retry)
fix
Check retryNum === 0 for the first retry attempt; increment logic accordingly.
affects: >=1.2.0
gotcharetryOnHttpResponse callback is called even on network errors (error.response may be undefined)
fix
Check if error has response property before accessing status codes.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
node-fetch v3+ is ESM-only, but this package uses require. Node-fetch version mismatch.
fix
Install node-fetch@2 or use dynamic import: const fetch = (...args) => import('node-fetch-retry-timeout').then(m => m.default(...args))
TypeError: fetch is not a function
Using named import { fetch } instead of default import.
fix
Use import fetch from 'node-fetch-retry-timeout' (ESM) or const fetch = require('node-fetch-retry-timeout') (CJS).
AbortError: The operation was aborted
Request timed out (timeout option). This is expected behavior.
fix
Increase timeout value or implement retry logic to handle timeouts gracefully.
ReferenceError: fetch is not defined
Running in environment without global fetch (e.g., old Node versions).
fix
Install node-fetch (v2) as a dependency and ensure it is available.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
node-fetchrequiredpeer dependency: provides the underlying fetch implementation
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
node-fetch-retry-timeout — npm install node-fetch-retry-timeout · libregistry