Originally published on proxymint.
Set an axios proxy on Node.js: the proxy object, auth, HTTPS_PROXY, https-proxy-agent with proxy: false, SOCKS5, rotation and the errors each mistake raises.
TL;DR
- Run npm ls axios before you debug anything else. From 1.16.1 the plain proxy object tunnels HTTPS through CONNECT; on 1.16.0 and older the proxy gets GET https://... in plain text, and many proxies answer that with 400 or 405.
- Add proxy: false whenever you pass your own agent. If HTTPS_PROXY is set, axios builds its own tunnel from it and your HttpsProxyAgent never sees the request, which is a fun one to chase.
- SOCKS5 needs socks-proxy-agent on httpAgent and httpsAgent. Use socks5h:// so the proxy resolves hostnames, and do not put a socks5:// URL in HTTPS_PROXY: axios speaks HTTP to it and the call just hangs.
- Keep protocol: 'http' even for HTTPS sites. It describes the hop to the proxy. protocol: 'https' on an ordinary proxy port ends in EPROTO ... packet length too long.
Key takeaways
- Put special-character passwords in the auth object. It takes the raw string, while an encoded password in HTTPS_PROXY reaches the proxy still encoded on 1.20.0 and comes back as a 407.
- Pair timeout with signal: AbortSignal.timeout(). The default timeout is 0, and on 1.20.0 timeout alone did not stop an HTTPS request stuck at an unanswered CONNECT.
- Count exits before you trust a rotating gateway. The built-in proxy object opens one tunnel per request, a keepAlive agent reuses one, and that can decide whether every-request rotation gives you a new IP.
- Check the exit IP on every new setup. adapter: 'fetch', a missing httpAgent and a NO_PROXY match all send traffic direct without an error.
Read the full guide on proxymint, with the commands, tables and sources.
Top comments (3)
The
proxy: falsegotcha when passing a customHttpsProxyAgentis such a classic time-sink—whenHTTPS_PROXYis present in the environment (often injected silently by a container or CI runner), Axios overrides the custom agent unlessproxy: falseis set explicitly. Similarly, pairingtimeoutwithAbortSignal.timeout()is essential in Node because Axios'stimeoutoption doesn't reliably abort a stalled TLS/CONNECT handshake on a dead proxy hop. Checking the exit IP directly on startup also catches silentNO_PROXYoradapter: 'fetch'fallbacks immediately before a scraper burns through local IP reputation.Easy test for which path won: put a wrong password in your agent. We did that on axios 1.20.0 with HTTPS_PROXY set and no proxy: false and still got a 200. The agent never saw the request.
Per-request rotation has a connection bill: keeping an exit sticky saves tunnel setup but changes the IP rotation you're paying for.