To use a proxy with node-fetch, create a proxy-aware Node.js agent and pass it in the request’s agent option. Setting HTTP_PROXY or HTTPS_PROXY alone does not configure node-fetch. The exact agent package and import syntax must match your installed versions.
This guide shows a complete CommonJS implementation, explains HTTPS destinations and proxy authentication, covers redirects and bypass rules, and distinguishes node-fetch from native fetch and Undici.
The basic node-fetch proxy pattern
The node-fetch 3.x README documents two accepted forms for agent: an Agent instance or a function that returns an Agent. A commonly used approach is https-proxy-agent. Confirm the current constructor and compatibility for the versions installed in your project before copying the example into production.
CommonJS example
const fetch = require('node-fetch');
const { HttpsProxyAgent } = require('https-proxy-agent');
const proxyUrl = process.env.HTTPS_PROXY;
if (!proxyUrl) {
throw new Error('Set HTTPS_PROXY to your proxy URL');
}
const agent = new HttpsProxyAgent(proxyUrl);
(async () => {
const response = await fetch('https://example.com', { agent });
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}
console.log(await response.text());
})();
Set the variable in the process environment rather than committing credentials to source control. For example, provide HTTPS_PROXY through your shell, container secret, CI secret store, or deployment configuration. The value must be a proxy URL accepted by the selected agent package, such as http://proxy.example:8080 or an authenticated URL supplied by your organization.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
ES modules
When your project uses ESM, use the import form supported by your installed node-fetch and agent-package versions:
import fetch from 'node-fetch';
import { HttpsProxyAgent } from 'https-proxy-agent';
const agent = new HttpsProxyAgent(process.env.HTTPS_PROXY);
const response = await fetch('https://example.com', { agent });
console.log(await response.text());
Do not assume that an import shown for one major release works unchanged in another. Check the package documentation and your package.json before changing module syntax.
HTTP versus HTTPS destinations
There are two protocols to consider: the URL you are fetching and the protocol spoken to the proxy. An HTTPS destination normally requires an agent that can establish a CONNECT tunnel through the proxy. An HTTP destination may use a different agent. Choose a package and agent class that explicitly support the combination in your deployment.
Use the right agent for the request
- HTTPS destination: use an HTTPS-capable proxy agent, as in the example above.
- HTTP destination: use an agent intended for HTTP proxying if your selected package requires one.
- Mixed destinations: provide an agent function that examines the URL and returns the appropriate agent.
For a redirect that changes from HTTP to HTTPS, a single hard-coded agent may be unsuitable. node-fetch permits an agent function, so you can select by destination URL:
const httpAgent = /* HTTP proxy agent for your package/version */;
const httpsAgent = /* HTTPS proxy agent for your package/version */;
const agent = parsedUrl => parsedUrl.protocol === 'https:'
? httpsAgent
: httpAgent;
const response = await fetch('http://example.com', { agent });
The exact agent constructors are package-version dependent; verify them before using this mixed-protocol form.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Proxy authentication and secure configuration
If the proxy requires credentials, use a secret-managed proxy URL or the authentication mechanism documented by your agent package. Never paste a real username, password, token, or private proxy hostname into a checked-in example, issue, log, or error message.
- Keep proxy values in environment variables or a secret manager.
- Restrict access to process environment and deployment logs.
- URL-encode special characters in credentials when the package expects credentials in a URL.
- Rotate credentials according to your organization’s policy.
After a failure, inspect status and error type without printing the complete proxy URL. A connection refusal usually indicates reachability or port problems; an authentication response indicates credentials or proxy policy; a TLS error can indicate an incompatible protocol or certificate-inspection setup.
Why HTTP_PROXY and HTTPS_PROXY do not automatically work
node-fetch does not automatically read HTTP_PROXY or HTTPS_PROXY merely because those variables exist. They are configuration inputs only when the client or wrapper explicitly reads them. With node-fetch, construct an agent and pass it through { agent }.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchA wrapper may add environment-variable behavior, but maintenance and compatibility vary. One registry listing for node-fetch-with-proxy showed version 0.1.6 published five years earlier; treat that as a signal to check its current release history, supported node-fetch major, and security posture rather than as a default recommendation.
Bypass rules and organizational proxies
Many corporate proxies should not receive internal hosts, localhost, or private network ranges. Define bypass behavior in the agent or runtime mechanism you choose, and document the intended scope. A bypass that is too broad can leak requests outside company controls; one that is too narrow can make internal services unreachable.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Test representative URLs: an external HTTPS site, an external HTTP site, an internal hostname that should bypass the proxy, and a destination that must be blocked by policy. Check the proxy’s access logs and your application’s error handling without exposing credentials.
Node.js built-in proxy support is a separate option
Recent Node.js releases document proxy support in Node’s own HTTP agents. The documentation for Node.js v26.10.0 describes enabling environment proxy handling with NODE_USE_ENV_PROXY=1 or --use-env-proxy, custom proxyEnv settings, proxy URL forms, and NO_PROXY patterns. The API is marked as active development, so verify the exact behavior for your runtime version.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
This runtime feature does not mean every node-fetch version will automatically honor those variables. node-fetch still uses its agent integration unless the particular combination of Node runtime, node-fetch release, and agent implementation documents otherwise. Treat runtime proxy configuration and node-fetch configuration as separate choices.
Do not confuse node-fetch, native fetch, and Undici
| Client | Proxy integration | What to verify |
|---|---|---|
| node-fetch | Pass an Agent instance or agent-returning function in agent. |
node-fetch major version, module syntax, destination protocol, and agent package API. |
| Native Node.js fetch | Uses Node’s fetch implementation and runtime networking stack. | Node version and whether the documented environment-proxy feature is enabled and supported. |
| Undici | Uses a ProxyAgent supplied as a dispatcher. |
Undici documentation and the dispatcher option; do not substitute node-fetch’s agent. |
Undici’s interface is intentionally different: a proxy is configured with a dispatcher, not node-fetch’s agent option. Code written for one client is not automatically portable to the others.
A production-ready request wrapper
Centralizing proxy construction makes timeouts, status handling, and logging consistent:
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
const fetch = require('node-fetch');
const { HttpsProxyAgent } = require('https-proxy-agent');
function createFetch() {
const proxy = process.env.HTTPS_PROXY;
if (!proxy) throw new Error('HTTPS_PROXY is required');
const agent = new HttpsProxyAgent(proxy);
return async function request(url, options = {}) {
const response = await fetch(url, {
...options,
agent: options.agent || agent,
});
if (!response.ok) {
const body = await response.text().catch(() => '');
throw new Error(`HTTP ${response.status} from ${url}: ${body.slice(0, 200)}`);
}
return response;
};
}
(async () => {
const request = createFetch();
const response = await request('https://example.com');
console.log(await response.text());
})();
Pass an explicit per-request agent when a destination needs different routing. Set reasonable request timeouts using the mechanism supported by your node-fetch version, and abort stalled requests so a dead proxy does not consume workers indefinitely.
Troubleshooting checklist
“The request ignores my proxy”
- Confirm that the code constructs an agent and passes
agentto fetch. - Do not rely on environment variables alone.
- Log the proxy host and port only, never credentials, to confirm the expected configuration loaded.
- Ensure the process is using the node-fetch instance you configured rather than native fetch or another HTTP library.
Connection refused or timeout
- Check DNS, firewall rules, port, and whether the proxy accepts connections from the application host.
- Confirm the proxy supports the destination protocol and CONNECT tunneling where required.
- Use a short timeout and retry only transient network failures, with backoff.
401, 407, or proxy-authentication failure
- Verify credentials and URL encoding.
- Check whether the proxy expects Basic, NTLM, Kerberos, a token, or an allow-list entry.
- Ask the proxy administrator whether the account may access the requested host and port.
TLS or certificate errors
- Check whether TLS is terminated and re-signed by an enterprise proxy.
- Install the organization’s trusted CA according to its security policy rather than disabling certificate verification.
- Ensure the agent’s protocol matches the proxy URL and destination.
Redirects fail after the first response
Inspect the redirect target. If it changes protocol, use an agent function that selects the correct agent for each URL, and review redirect limits and credential-forwarding behavior.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Performance, reliability, and cost considerations
Reusing one agent can avoid repeatedly establishing proxy connections. Keep connection pooling aligned with the proxy’s limits, and avoid unbounded concurrency that overwhelms either the proxy or destination. Measure DNS, connection, TLS, proxy queue, and server timing separately when diagnosing latency.
An organizational proxy may already provide the endpoint you need; buying a proxy service is optional, not a requirement of node-fetch. If you do use a commercial endpoint, evaluate its authorization, geography, logging policy, protocol support, rate limits, and contract terms independently.
Or skip the browser setup
If your actual goal is generating clean website screenshots rather than routing an HTTP API request, ScreenshotNeo provides a single-call screenshot API and MCP server. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.
cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
See the ScreenshotNeo documentation for all options, including full-page and element capture, device presets, dark mode, custom CSS and JavaScript, waits, blocking rules, headers and cookies, PDFs, caching, signed links, webhooks, bulk capture, and MCP tools for AI clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Frequently Asked Questions
Can I pass a proxy URL directly to node-fetch?
No. Construct a compatible Agent and pass it with the request’s agent option; a URL by itself is not the node-fetch proxy configuration.
Is a paid proxy required?
No. An existing company or network proxy is sufficient if it permits the destination and your agent supports the required protocols.
Can I use the same proxy code with Undici?
Not unchanged. Undici uses a ProxyAgent through the dispatcher option, while node-fetch uses agent.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsShould I disable TLS verification when a proxy causes certificate errors?
No. Resolve the trust-chain or enterprise-CA configuration instead of disabling certificate verification.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

