Using our proxies with Node.js
Node.js fetch is built on undici. A ProxyAgent passed as the dispatcher sends requests through the proxy; recent Node versions can also read proxy settings from environment variables.
Pick a proxyCompatibility
- undici ProxyAgent takes the proxy URI; credentials in the URI are used for a Basic Proxy-Authorization header (the token option is the alternative).
- Pass the agent per request with fetch(url, { dispatcher }) or for all requests with setGlobalDispatcher().
- https:// targets go through an HTTP CONNECT tunnel; socks5:// URIs are handed to undici's Socks5ProxyAgent.
- EnvHttpProxyAgent reads HTTP_PROXY, HTTPS_PROXY and NO_PROXY (lowercase wins if both are set).
- Node.js v24.5.0 / v22.21.0 added built-in proxy support enabled with NODE_USE_ENV_PROXY=1 or --use-env-proxy (stability 1.1, active development).
- Protocols:
- HTTP, HTTPS (CONNECT), SOCKS5
- Connection:
- Username and password, IP allowlist
Configuration
// check-ip.mjs — npm install undici
import { fetch, ProxyAgent } from "undici";
const dispatcher = new ProxyAgent("http://USERNAME:PASSWORD@PROXY_HOST:PORT");
const res = await fetch("https://api.ipify.org?format=json", { dispatcher });
console.log(await res.json());The sample uses the undici package's fetch with a ProxyAgent dispatcher so it does not depend on the Node version's built-in proxy support. For IP allowlist access, drop USERNAME:PASSWORD@ from the URI.
PROXY_HOST, PORT, USERNAME and PASSWORD are placeholders. After we select proxies for your task, we send you the real host, port and credentials.
Check the result
node check-ip.mjs
// expected output: { ip: '<exit IP>' }- Run node check-ip.mjs and confirm the printed ip equals the exit IP we sent you.
- Look up the exit IP in two independent GeoIP services and confirm both show the country (and city, if you asked for one) from your request. GeoIP databases can disagree; tell us if they do.
- Request one page of your own site or a permitted source with the same dispatcher and check status code and content for that country.
What to put in the request
- Node.js version and HTTP client (fetch/undici, or another library).
- Protocol: HTTP or SOCKS5; access by username/password or IP allowlist.
- Country, session mode and the number of parallel connections.
- The task: monitoring, QA of your own service, or permitted public data.
Common pitfalls
- Setting HTTPS_PROXY and expecting plain fetch to use it: Node only honours these variables with NODE_USE_ENV_PROXY=1 / --use-env-proxy (v24.5.0, v22.21.0 and later) or an EnvHttpProxyAgent dispatcher.
- Passwords with special characters not URL-encoded in the proxy URI; undici URL-decodes credentials before encoding them.
- Mixing the global fetch with an agent from a separately installed undici version; import fetch and ProxyAgent from the same package, as in the sample.
Recommended proxy types
Sources
Not sure which proxy fits?
Describe the task in two sentences. We reply with a concrete setup and price, usually within one business day.
Availability, exact parameters and price are confirmed in our reply after manual selection. Nothing is charged automatically.