Registry / devops / fetch-timeout

fetch-timeout

JSON →
library0.0.2jsnpmunverified

Thin wrapper around the native fetch (or node-fetch) that adds configurable timeout support, returning a custom error string when the timeout is exceeded. Version 0.0.2 is the latest stable release; the package is minimal and has no active development. Only suitable for simple timeout scenarios; does not support AbortController or signal-based cancellation. Alternatives include native AbortController (now widely supported) or libraries like 'ky' with built-in timeout.

npm install fetch-timeout
INSTALL
IMPORT
SIG · FETCH-TIMEOUT
F
fetch-timeout
devopsjavascriptv0.0.2
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
import fetchTimeout from 'fetch-timeout'
const fetchTimeout = require('fetch-timeout')
Library uses CommonJS but also provides a default export for ES6 modules. The require() works as well.
fetchTimeout
const fetchTimeout = require('fetch-timeout')
import { fetchTimeout } from 'fetch-timeout'
No named export; only default export is available.
fetchTimeout (ES5)
let fetchTimeout = require('fetch-timeout')
let fetchTimeout = require('fetch-timeout').default
In CommonJS, the default export is directly the require result, no .default needed.

Demonstrates using fetch-timeout to perform a GET request with a 5-second timeout and custom error string.

// Node.js usage const fetchTimeout = require('fetch-timeout'); fetchTimeout('https://api.github.com/', { method: 'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, }, 5000, 'Request timed out') .then(res => { if (res.status !== 200) { throw new Error(`Status code not OK: ${res.status}`); } return res.json(); }) .then(json => { console.log('JSON response:', json); }) .catch(err => { console.error('Error:', err); });
Debug
Known issues
deprecatedPackage uses node-fetch v1.x as peer dependency, which is outdated and has known issues.
fix
Upgrade to node-fetch v2 or v3 and use native AbortController for timeout.
affects: >=0.0.0
gotchaThe timeout option does NOT cancel the underlying fetch request; the promise may still complete after timeout.
fix
Use AbortController for proper cancellation if needed.
affects: >=0.0.0
gotchaIn Node.js, you must install node-fetch as a peer dependency even if not explicitly listed; window.fetch is not available.
fix
Run 'npm install node-fetch@^1.6.3'
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: fetch is not a function
Missing node-fetch peer dependency in Node.js environment.
fix
Install node-fetch: npm install node-fetch@^1.6.3
Error: Timeout error
Default timeout (10s) exceeded when no custom error string is provided.
fix
Increase timeout value or ensure server responds faster.
Cannot find module 'node-fetch'
node-fetch not installed but required for Node.js.
fix
Install node-fetch: npm install node-fetch
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
node-fetchoptionalPeer dependency required in Node.js environments where window.fetch is unavailable
Agent activity
5 hits · last 30 days
node
4
Resources
fetch-timeout — npm install fetch-timeout · libregistry