node-fetch-with-proxy
raw JSON → 0.1.6 verified Sat May 09 auth: no javascript
Thin wrapper around node-fetch that transparently uses HTTP_PROXY/HTTPS_PROXY environment variables for proxy support. Version 0.1.6, stable but low update cadence (last update 2019). Key differentiator: drop-in replacement for node-fetch that requires no code changes — just set proxy env vars. Unlike node-fetch's native proxy options, it uses proxy-agent under the hood for comprehensive protocol support (http, https, socks).
Common errors
error Error: getaddrinfo ENOTFOUND proxy.example.com ↓
cause Proxy hostname cannot be resolved.
fix
Verify HTTP_PROXY value is correct and DNS resolves the proxy host.
error TypeError: fetch is not a function ↓
cause Using named import instead of default import.
fix
Use 'import fetch from 'node-fetch-with-proxy'' (no curly braces).
error SyntaxError: Cannot use import statement outside a module ↓
cause Trying to use ESM import in a CommonJS file without type:module.
fix
Add 'type': 'module' in package.json or use require().
Warnings
gotcha HTTP_PROXY is used for both http and https requests; use NO_PROXY to bypass proxy for specific hosts. ↓
fix Set NO_PROXY env var (comma-separated list of hostnames) to exclude from proxy.
gotcha Environment variables are only read once at import time; changing them later has no effect. ↓
fix Set env vars before importing the package.
breaking node-fetch v3 is ESM-only; this wrapper may not be compatible with node-fetch v3 due to CJS dependencies. ↓
fix Use node-fetch v2 or check compatibility; consider using native fetch (Node 18+).
deprecated Package last updated in 2019; no known issues but may lack modern node-fetch features. ↓
fix Consider native fetch or alternatives like undici with proxy support.
Install
npm install node-fetch-with-proxy yarn add node-fetch-with-proxy pnpm add node-fetch-with-proxy Imports
- fetch wrong
const fetch = require('node-fetch-with-proxy')correctimport fetch from 'node-fetch-with-proxy' - default
import fetch from 'node-fetch-with-proxy' - Headers wrong
import { Headers } from 'node-fetch-with-proxy'correctimport { Headers } from 'node-fetch'
Quickstart
import fetch from 'node-fetch-with-proxy';
process.env.HTTP_PROXY = process.env.HTTP_PROXY || 'http://proxy.example.com:8080';
async function main() {
try {
const res = await fetch('http://httpbin.org/get');
const data = await res.json();
console.log(data);
} catch (err) {
console.error('Fetch failed:', err.message);
}
}
main();