Geonode logo
Library and script errors

How to Fix axios Proxy Not Working in Node.js

Find which axios setting misroutes the request, then fix it with Node.js code or a few variables.

Updated

TL;DR

When axios skips or breaks a proxy, the cause usually sits in axios: versions up to 1.16.0 send https:// requests to the proxy as plain text, and a proxy environment variable can replace your agent. The fastest fix is axios 1.16.1 or later, which opens a CONNECT tunnel.

What a broken axios proxy looks like

As console.log(err) prints them; axios keeps Node.js's message, and OpenSSL details vary by Node.js version.

WhereWhat you see
axios 1.16.0 or older, https:// URL, proxy that closes non-CONNECT requests (code ECONNRESET)AxiosError: socket hang up
axios 1.16.0 or older, proxy object without protocol (Node.js 20, OpenSSL 3.0)AxiosError: write EPROTO ... SSL routines:ssl3_get_record:wrong version number ...
axios with protocol https on an HTTP proxy port (Node.js 24.22, OpenSSL 3.5)AxiosError: write EPROTO ... SSL routines:tls_validate_record_header:wrong version number ...
axios, proxy refused the loginAxiosError: Request failed with status code 407
axios 1.20 with httpVersion: 2 and a proxyAxiosError: HTTP/2 requests with a proxy are not supported
curl -v through the same proxy, for comparison* CONNECT tunnel established, response 200

Why this happens

Older axios asks the proxy to fetch HTTPS pages instead of opening a tunnel.

Up to 1.16.0, axios writes the full https:// URL, headers and body to the proxy unencrypted, and a proxy that expects CONNECT may close the connection. A proxy object without protocol makes it start TLS with the proxy instead.

Diagnose your axios proxy first

Start in your lockfile, then compare axios with curl and read the proxy settings it picks up.

  • Open package-lock.json and find every key ending in node_modules/axios; a version of 1.16.0 or older sends https:// requests in plain text.

  • Run curl -v -x with the same proxy URL and target; if curl shows CONNECT and a 200, the proxy works and axios is misconfigured.

  • Run env | grep -i proxy in the shell that starts the script; any line you did not expect names a proxy axios may use.

  • If the error says write EPROTO, axios opened TLS to a plain HTTP port; look for protocol https or HTTPS_PROXY without http://.

Solutions ranked by effectiveness

Upgrade first; use the agent when an old axios must stay, and check environment variables last.

  1. Most common fix

    Upgrade axios and spell out the proxy

    Applies when the lockfile shows 1.16.0 or older. After upgrading, name protocol http for Geonode's HTTP port and pass the login as an auth object, not inside a URL.

    // npm install axios@1
    const axios = require("axios");
    
    const proxy = {
      protocol: "http",
      host: "proxy.geonode.io",
      port: 9000,
      auth: { username: "USERNAME", password: "PASSWORD" },
    };
    axios.get("https://example.com/", { proxy })
      .then((res) => console.log(res.status))
      .catch((err) => console.log(err.code, err.message));
  2. Check next

    Let https-proxy-agent own the tunnel

    Applies when you cannot upgrade axios yet or already manage agents yourself. Keep proxy: false, or a matching HTTPS_PROXY or ALL_PROXY variable replaces your agent.

    // npm install axios https-proxy-agent@7
    const axios = require("axios");
    const { HttpsProxyAgent } = require("https-proxy-agent");
    
    const proxy = "http://USERNAME:PASSWORD@proxy.geonode.io:9000";
    const agent = new HttpsProxyAgent(proxy);
    const client = axios.create({ httpsAgent: agent, proxy: false });
    
    client.get("https://example.com/")
      .then((res) => console.log(res.status))
      .catch((err) => console.log(err.code, err.message));
  3. For developers

    Make proxy environment variables explicit

    Applies when axios uses a proxy that is not in your code. axios reads these variables only when the request config has no proxy field.

    1. Write HTTPS_PROXY as a full URL: http://USERNAME:PASSWORD@proxy.geonode.io:9000.

    2. Remove a lower-case https_proxy that differs; axios reads it before HTTPS_PROXY.

    3. Add local and internal hosts to NO_PROXY, separated by commas.

    4. Pass proxy: false on clients that must connect directly.

Stop the axios proxy failure from coming back

Habits for Node.js projects where several packages bring their own axios and every request must use the proxy.

  1. Add an npm overrides entry for axios so nested dependencies cannot install a copy older than 1.16.1.

  2. Build one axios instance with the proxy settings in a shared module and import it instead of global axios.

  3. Read the axios changelog for proxy entries before upgrading; 1.16.1 and 1.18.1 both changed proxy handling.

  4. On Node.js 22.21+ or 24.5+, NODE_USE_ENV_PROXY=1 makes Node, not axios 1.18.1+, read proxy variables; set it deliberately.

See requests that reach the proxyGeonode's Statistics section counts successful and failed requests made through your proxies.
Try residential proxies

Related errors

Learn more

FAQ

Yes, if the proxy port itself speaks TLS: protocol https encrypts the hop to the proxy as well. Geonode's HTTP ports, such as 9000, take an http:// proxy URL and still reach https:// sites through a tunnel.

No. axios documents that option for Node.js only. In Chrome and other Chromium browsers, page requests follow the system network settings, so configure the proxy there or move the call to a server.

Yes, whenever a proxy variable might be set. axios 1.16.1 and later step aside only for the HttpsProxyAgent class from their own https-proxy-agent 5 dependency, so an https-proxy-agent@7 agent is swapped for axios's own tunnel.

axios builds the login from the URL's password as stored, still percent-encoded, so p%40ss reaches the proxy instead of p@ss. Put the password in the proxy auth object, which axios sends unchanged.

No. With adapter set to fetch, axios passes the request to fetch() and never reads proxy, httpAgent or httpsAgent. In Node.js, keep the default http adapter for proxied requests.

No. With httpVersion: 2, axios 1.20 rejects any request that has a proxy set, and it skips proxy variables, so those requests connect directly. Leave httpVersion at 1 for proxied requests.

Whitelist servers from deploy scripts

Geonode's whitelisting API adds your server IPs, so axios sends no proxy login.