Registry / devops / hardened-fetch

hardened-fetch

JSON →
library2.0.0jsnpmunverified

Hardened Fetch is a lightweight wrapper around global.fetch for Node.js (v20+) that adds request timeouts, throttling, rate limit awareness, retries with exponential backoff, and descriptive error messages. It is designed for building robust API clients and web scrapers without external SDKs. Version 2.0.0 is actively maintained, ships with TypeScript definitions, and focuses on configurability—allowing control over concurrency, rate limits, retry policies, and abort signals. Key differentiators: small footprint, no dependencies, and built-in rate limit header parsing.

npm install hardened-fetch
INSTALL
IMPORT
SIG · HARDENED-FETCH
H
hardened-fetch
devopsjavascriptv2.0.0
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.

HardenedFetch
import { HardenedFetch } from 'hardened-fetch'
import HardenedFetch from 'hardened-fetch'
ESM-only since v2.0.0; named export only. No default export.
HardenedFetch
import { HardenedFetch } from 'hardened-fetch'
const { HardenedFetch } = require('hardened-fetch')
CommonJS require is not supported in v2.0.0 (ESM-only). Use dynamic import() if needed.
HardenedFetchOptions
import type { HardenedFetchOptions } from 'hardened-fetch'
Type-only import for TypeScript users. Not available at runtime.

Creates a HardenedFetch client with custom retry and throttle options, fetches a resource, and handles errors.

import { HardenedFetch } from 'hardened-fetch' const client = new HardenedFetch({ baseUrl: 'https://swapi.dev/api/', maxRetries: 3, maxInProgress: 10, maxPerInterval: 5, intervalLength: 1000, }) async function main() { try { const response = await client.fetch('/species/1') const data = await response.json() console.log(data) } catch (error) { console.error('Fetch failed:', error.message) } } main()
Debug
Known issues
breakingv2.0.0 removed CommonJS support; the package is ESM-only and requires Node.js >=20.
fix
Migrate to ESM syntax (import/export) and update Node.js to 20+.
affects: >=2.0.0
breakingv2.0.0 renamed the constructor from 'Fetch' to 'HardenedFetch'. The old name is no longer exported.
fix
Replace 'new Fetch(...)' with 'new HardenedFetch(...)'.
affects: >=2.0.0
deprecatedThe 'retryMethods' option from v1.x has been replaced by 'doNotRetryMethods' (inverted logic).
fix
Use 'doNotRetryMethods' to list methods that should NOT be retried.
affects: >=2.0.0
gotchaIf no rate limit headers are found in the response, the client will not parse rate-limit resets and may retry aggressively.
fix
Ensure your API returns headers matching the 'rateLimitHeaders' list, or disable rate-limit-based retries by setting an empty array.
affects: >=1.0.0
gotchaThe 'timeout' parameter in client.fetch() sets the request timeout via AbortController; the global fetch timeout is ignored.
fix
Pass timeout as third argument to client.fetch(), not in the init object.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: Must use import to load ES Module: .../node_modules/hardened-fetch/...
Using require() with an ESM-only package version 2.x.
fix
Use import statements or dynamic import() instead of require().
TypeError: client.fetch is not a function
Importing the default export instead of the named export HardenedFetch.
fix
Use import { HardenedFetch } from 'hardened-fetch'
Error: Request failed after 3 retries: ...
Exceeded maxRetries due to persistent network or server errors.
fix
Check network connectivity, increase maxRetries, or add error handling.
AbortError: The operation was aborted
Request timeout reached before response.
fix
Increase the timeout value passed to client.fetch() or improve network latency.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
hardened-fetch — npm install hardened-fetch · libregistry