Registry / ai-ml / fetch-h

fetch-h

JSON →
library3.0.2jsnpmunverified

A Fetch API client for Node.js that supports HTTP/1.1 and HTTP/2 with automatic protocol negotiation via ALPN. Current stable version is 3.0.2, published on npm, with semi-regular releases. Key differentiators include transparent HTTP/2 support, cookie management, built-in response compression (br, gzip, deflate), and TypeScript types. It uses the native Node.js http, https, and http2 modules without external dependencies, and manages sessions and socket reuse automatically. It provides a familiar browser-like fetch API extended for Node.js streams and offers context-based cookies and custom decoders.

npm install fetch-h
INSTALL
IMPORT
SIG · FETCH-H
F
fetch-h
ai-mljavascriptv3.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.

fetch
import { fetch } from 'fetch-h2'
import fetch from 'fetch-h2'
fetch is a named export, not a default export. Common mistake when migrating from node-fetch.
Headers
import { Headers } from 'fetch-h2'
const { Headers } = require('fetch-h2')
ESM-only package since v3; CommonJS require() will fail. Use import syntax.
AbortController
import { AbortController } from 'fetch-h2'
import { AbortController as AC } from 'fetch-h2'; const controller = new AC();
AbortController is a named export. Renaming is fine but unnecessary.

Performs a GET request to httpsbin.org using fetch-h2, checks the response status, and parses JSON body.

import { fetch } from 'fetch-h2'; async function main() { try { const response = await fetch('https://httpbin.org/get', { headers: { 'User-Agent': 'fetch-h2/3.0' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); } catch (error) { console.error('Fetch failed:', error); } } main();
Debug
Known issues
breakingRequires Node.js >= 12 for version 3.x. Node.js 10 support dropped.
fix
Upgrade Node.js to 12 or higher.
affects: >=3.0.0
breakingESM-only package since version 3.0.0. CommonJS require() will throw an error.
fix
Use import syntax (e.g., import { fetch } from 'fetch-h2') or switch to dynamic import().
affects: >=3.0.0
deprecatedThe 'context' export is deprecated in favor of per-request options.
fix
Pass context options directly to fetch() instead of using context().
affects: >=2.0.0
gotchafetch() does not follow redirects automatically by default; you must set 'redirect: 'follow' option.
fix
Example: fetch(url, { redirect: 'follow' })
affects: *
gotchaHTTP/2 connections over plain-text require 'http2://' scheme; 'http://' defaults to HTTP/1.1.
fix
Use 'http2://' for h2c connections.
affects: *
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/fetch-h2/... not supported
Requiring an ESM-only package with CommonJS require() in Node.js 12+.
fix
Use dynamic import() or switch to ES modules (e.g., "type": "module" in package.json).
TypeError: fetch is not a function
Importing the default export instead of named export.
fix
Use import { fetch } from 'fetch-h2' instead of import fetch from 'fetch-h2'.
TimeoutError: The operation was aborted
The request exceeded the default timeout (usually no timeout set but explicit abort).
fix
Set a timeout via AbortController or use the 'timeout' option if supported (community note: not officially documented).
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
fetch-h — npm install fetch-h · libregistry