Authenticated proxies in Node.js: Axios, native fetch and Got

Updated:

The reliable way to use a Node.js proxy with Axios is an HttpsProxyAgent passed as httpsAgent, together with proxy: false. Axios's own proxy: { host, port } setting does not open an HTTP CONNECT tunnel, so it breaks on https:// URLs; native fetch() needs an undici ProxyAgent instead. This page shows each client with a ProxyV4 http://user:pass@ip:port URL and how to confirm the exit IP.

Node.js (Axios / Undici) · HTTP Proxy Format
new HttpsProxyAgent('http://user:pass@ip:port')

Pick the snippet for your HTTP client

All three clients take the same proxy URL. Build it from the ip:port:user:pass line in your order; the scheme stays http:// because the client speaks HTTP to the proxy and tunnels TLS through it.

ClientInstallProxy wiring
Axiosnpm i https-proxy-agentaxios.get(url, { httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port'), proxy: false })
Native fetch (Node 18+)npm i undicifetch(url, { dispatcher: new ProxyAgent('http://user:pass@ip:port') })
Gotnpm i hpagentgot(url, { agent: { https: new HttpsProxyAgent({ proxy: 'http://user:pass@ip:port' }) } })

Why `proxy: false` matters in Axios

Axios checks the HTTP_PROXY and HTTPS_PROXY environment variables on its own. If one of them is set on the machine (common in CI runners and containers) and you also pass an agent, the two configurations collide. proxy: false tells Axios to ignore the environment and its built-in proxy logic, so the agent is the only thing deciding where the request goes.

Reusing agents across many requests

  • Create one agent per proxy IP outside your request loop; the agent holds keep-alive sockets, and a new agent per call throws them away
  • With several proxies, keep a Map from IP to agent and pick from it, rather than building agents on the fly
  • Give every call a timeout (for example timeout: 10000 in Axios) so one stalled target does not hold a worker forever
  • Need the proxy list as data? The proxy format converter turns ip:port:user:pass lines into a JSON array you can require or import

What a stable IP gives a Node.js job

A ProxyV4 private IPv4 belongs to one customer for the whole rental and keeps the same address when you renew, so an allow-listed API, a logged-in session or a rate-limit budget tied to that IP stays valid between deploys. Bandwidth is not metered, which keeps long-running workers predictable. For crawling patterns and pacing, see the web scraping use case.

Step by step

  1. 1

    Install the client and the agent

    Run npm install axios https-proxy-agent in the project (or npm install undici if you use native fetch).

  2. 2

    Build the agent once

    Create const agent = new HttpsProxyAgent('http://user:pass@ip:port'); with the values from your ProxyV4 order.

  3. 3

    Send a request through it

    Call const res = await axios.get('https://proxyv4.com/api/my-ip', { httpsAgent: agent, proxy: false, timeout: 10000 });.

  4. 4

    Compare the IP

    console.log(res.data) should print the proxy IP. If it prints your server's own address, the agent was not applied.

Frequently asked questions

Why does Axios `proxy: { host, port, auth }` fail on HTTPS sites?

That option sends an ordinary HTTP request to the proxy instead of first asking for an HTTP CONNECT tunnel, so TLS to the target never gets set up properly. Use httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port') and set proxy: false.

How do I add a proxy to native `fetch()` in Node 18, 20 or 22?

Node's fetch runs on undici, so import ProxyAgent from undici and pass { dispatcher: new ProxyAgent('http://user:pass@ip:port') } as part of the fetch() options.

My password contains `@` or `:`. Will the URL break?

It can, because those characters have meaning inside a URL. Percent-encode the password with encodeURIComponent(password) before you build http://user:pass@ip:port.

The request returns 407. What is wrong?

The proxy answered but rejected the login. Recheck the username and password from your order; the 407 troubleshooting page lists the common causes.

Static IPv4 for your Node.js workers

Private IPv4 in 7 countries plus static ISP in the US and Vietnam, unmetered, one customer per IP. Buy one or many.

Check live US prices

Related articles

Proxies by platform
Proxies for web scraping: a fixed pool of IPs with unmetered traffic
Web scraping proxies for Python, Scrapy, Playwright and Selenium: a pool of private IPv4 and static ISP addresses, unlimited bandwidth, flat per-IP pricing.
Proxy setup
Puppeteer with an authenticated proxy: launch flag plus login
Point Puppeteer at an HTTP(S) proxy with --proxy-server, log in with page.authenticate() on every tab, and run several IPs in one Chrome via browser contexts.
Proxy setup
Playwright proxy authentication, one static IP per context
Give each Playwright browser context its own authenticated HTTP(S) proxy in Node.js or Python, match timezone and locale to the IP and confirm the exit address.
Free tools
Rewrite a proxy list into the format your tool expects
Convert proxy lists in your browser between ip:port:user:pass, user:pass@ip:port, http:// URLs, SOCKS5 URIs, JSON arrays and FoxyProxy import files, in bulk.
Proxies by platform
Proxies for SEO rank tracking: see the results page a local searcher sees
SEO rank tracking proxies with a private IPv4 in the US, UK, Vietnam, Japan and four more markets, so rankings, local packs and ads match what locals see.
Proxies by platform
Discord proxies for running several accounts without group-wide phone locks
Discord proxies that put each account and token on its own static IP, so one invite join does not phone-lock the group. US, Singapore and Vietnam options.
IPV4 · united states
Build a US IP Pool for Scraping, Rank Tracking and Ad Checks
Buy US private IPv4 proxies: static American datacenter IPs, one customer per IP, unlimited bandwidth. Built for scraping, SERP tracking and US ad checks.
IPV4 · singapore
One Fixed Singapore IP for Every Regional Store and Ad Account
Singapore private IPv4 proxy: a static SG datacenter IP used by you alone, for Lazada and Shopee SG stores, Singapore ad accounts and regional automation.