How to Use Proxies with node-fetch

node-fetch mirrors the browser Fetch API, which is great for portability but means it has no built-in way to route traffic through an intermediary. To wire up a node-fetch proxy you lean on Node’s HTTP agent system, passing a proxy-aware agent through the request options instead of a config flag.

That one detail shapes the rest: which helper package you install, how credentials attach, and whether HTTPS targets tunnel cleanly. Here’s the practical picture, without pretending one setup fits every job.

Using proxies with node-fetch

  1. Get proxy credentials

    Obtain host, port and auth from your provider.

  2. Configure node-fetch

    Set the proxy in your node-fetch request or launch options.

  3. Rotate & retry

    Rotate IPs and handle bans/timeouts for reliable runs.

Which proxy type

Proxy typeWhen to use it
ResidentialIPs assigned by ISPs to real home users; hardest to detect, best for sensitive targets.
DatacenterFast, cheap IPs from cloud/hosting providers; ideal for tolerant targets and high throughput.
ISPDatacenter-hosted IPs registered under ISPs; residential legitimacy with datacenter speed and stable sessions.

Our verdict

For a value-minded developer, the win is choosing a provider whose proxy plays nicely with a standard agent: clean credential-in-URL auth, working HTTPS CONNECT tunneling, and optional SOCKS5. Confirm those before you commit, and rotation or sticky sessions become a one-line change rather than a rewrite.

Frequently asked questions

No. node-fetch follows the Fetch spec, which has no proxy option, so you route requests by passing an HTTP or HTTPS agent (commonly from https-proxy-agent or hpagent) through the request’s agent field. Your provider credentials sit in the proxy URL or an auth header.

Swap the HTTP agent for a SOCKS-capable one such as socks-proxy-agent, built from your provider’s socks5:// endpoint, and hand it to the agent option. Check first that your plan actually exposes SOCKS5, since some proxies sell only HTTP and HTTPS.

HTTPS targets need the proxy to tunnel via the CONNECT method, so a plain HTTP agent is not enough on its own. Use an https-proxy-agent-style agent, and treat a 407 response as a credentials problem rather than a tunneling fault.

Pass a function to the agent option that returns a freshly built proxy agent on each call, or point every request at a providers rotating gateway that swaps the exit IP for you. When you need a stable identity, look for username-based session controls instead.

Related proxy guides

Proxy Ranked is an independent comparison resource. Labels are qualitative, not numeric rankings.