Registry / devops / fetch-with-proxy

fetch-with-proxy

JSON →
library3.0.1jsnpmunverified

A wrapper around node-fetch that automatically uses HTTP(S) proxy settings from environment variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY). Version 3.0.1, stable, low maintenance. Unlike tunnel-based solutions (e.g., request, proxy-agent), it uses direct HTTP connections without CONNECT tunneling for HTTP targets, which avoids certain compatibility issues but may not support HTTPS proxying. It is a thin wrapper, passing through most node-fetch API behavior.

npm install fetch-with-proxy
INSTALL
IMPORT
SIG · FETCH-WITH-PROXY
F
fetch-with-proxy
devopsjavascriptv3.0.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
import fetch from 'fetch-with-proxy'
const { default: fetch } = require('fetch-with-proxy')
ESM-only since v3.0.0. For CommonJS, use dynamic import or switch to CJS-compatible version.
RequestInit
import type { RequestInit } from 'node-fetch'
import { RequestInit } from 'fetch-with-proxy'
Types are re-exported from node-fetch, but directly importing from node-fetch is safer.
Headers
import { Headers } from 'node-fetch'
import { Headers } from 'fetch-with-proxy'
fetch-with-proxy does not re-export Headers, Response, etc. Import from node-fetch.

Demonstrates default import and automatic proxy detection from environment variables.

import fetch from 'fetch-with-proxy'; const url = 'https://example.com'; const proxyUrl = process.env.HTTP_PROXY || 'http://proxy.example.com:8080'; // The proxy is detected from environment variables automatically. // Example: set HTTP_PROXY=http://proxy.example.com:8080 fetch(url) .then(response => response.text()) .then(body => console.log(body)) .catch(err => console.error(err));
Debug
Known issues
breakingv3.0.0 dropped CommonJS support; now ESM-only.
fix
Use dynamic import: const fetch = await import('fetch-with-proxy'); or downgrade to v2.x if CJS required.
affects: >=3.0.0
gotchaDoes NOT support CONNECT tunneling for HTTPS proxies when fetching HTTP URLs. Only HTTP-to-HTTP and HTTPS-to-HTTPS (via agent) proxying.
fix
Use a tunnel-based library like https-proxy-agent if you need full CONNECT tunneling.
affects: all
deprecatednode-fetch v2 is deprecated; fetch-with-proxy v3 requires node-fetch v3 (ESM).
fix
Upgrade node-fetch to v3 or stay on fetch-with-proxy v2 which supports node-fetch v2.
affects: >=3.0.0
gotchaDoes not set any default User-Agent header; relies on node-fetch defaults.
fix
Explicitly set headers if required.
affects: all
gotchaProxy environment variables are read only once at startup, not on each request.
fix
Restart process if environment changes, or use custom agent for dynamic proxy.
affects: all
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
ESM import used in a CommonJS project without appropriate configuration.
fix
Add "type": "module" to package.json or use .mjs extension, or use dynamic import.
TypeError: fetch is not a function
Incorrect import path or using v3 as require().
fix
Use import fetch from 'fetch-with-proxy' (ESM) or const fetch = (await import('fetch-with-proxy')).default; for CJS.
Error: Invalid protocol: http:
Trying to fetch an HTTP URL through an HTTP proxy that doesn't handle CONNECT.
fix
Use an HTTPS URL or switch to a tunnel-based proxy agent.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
node-fetchrequiredCore dependency: fetch-with-proxy wraps node-fetch to add proxy support.
Agent activity
4 hits · last 30 days
node
4
Resources
fetch-with-proxy — npm install fetch-with-proxy · libregistry