← Guides

Send Node.js fetch and Axios through an HTTPS proxy

Use a proxy agent on the requests that need a fixed IP. A dedicated proxy or an authenticated proxy on your own VPS can serve that role.

Updated 2026-11-24 · 5 min read

Set up a proxy user

Request route through your static IP Node.js application your code proxy (HTTPS) Your server 203.0.113.42 from 203.0.113.42 Partner API / DB allows 203.0.113.42
Only the calls you send through the proxy use your static IP. Every other request goes out directly, as before.
  1. Log in to the client area, open My Services and click your server. Scroll to Use your IP from code, n8n, CI or a browser. Under Add a proxy user, type node and click Add.
    MazeVPN client area: Add a proxy user, with the name node typed in
    You should see: a new card named app-node. Names can use letters and digits only, and MazeVPN adds the app- prefix.
  2. On that card, click Copy next to HTTPS proxy (marked Encrypted). The copied URL contains the password, so paste it only into a secret or environment variable, never into code.
    MazeVPN client area: the card of proxy user app-ci with its HTTPS, HTTP and SOCKS5 proxy URLs and Copy buttons
    The card of a new proxy user. The eye icon shows the password; Copy copies the full URL with the password. (Server IP replaced with an example.)
    You should see: a URL like https://app-node:…@203.0.113.42:443, where the address is your server’s IP.
  3. Install the libraries. Store the HTTPS proxy URL in MAZE_PROXY_URL. Pick package releases compatible with your Node version.
    npm install undici axios https-proxy-agent
    You should see: The three modules install. The example URL format is https://app-node:PASSWORD@203.0.113.42:443.

Fetch: use a dispatcher

Node’s global fetch is available starting in Node 18. It has no proxy URL option in the fetch request settings. Pass an Undici dispatcher on Node versions that support it. Check the installed Undici release’s engine requirements separately.

For an HTTPS proxy addressed by IP, the MazeVPN example uses a placeholder TLS server name and explicitly verifies the proxy certificate against the actual IP. Normal certificate chain verification still applies. A hostname-based proxy uses the normal TLS path.

// fetch-check.mjs
import { isIP } from 'node:net';
import { checkServerIdentity } from 'node:tls';
import { Agent, ProxyAgent } from 'undici';

const url = 'https://api.ipify.org';
const proxy = new URL(process.env.MAZE_PROXY_URL);
const host = proxy.hostname.replace(/^\[|\]$/g, '');
const proxyTls = proxy.protocol === 'https:' && isIP(host)
  ? { servername: 'proxy.invalid',
      checkServerIdentity: (_name, cert) => checkServerIdentity(host, cert) }
  : undefined;
const direct = new Agent();
const proxied = new ProxyAgent({ uri: proxy.href, proxyTls });

try {
  for (const [label, dispatcher] of [['direct', direct], ['proxy', proxied]]) {
    const r = await fetch(url, { dispatcher, signal: AbortSignal.timeout(15_000) });
    if (!r.ok) throw new Error('IP check failed: ' + r.status);
    console.log(label, (await r.text()).trim());
  }
} finally {
  await direct.close();
  await proxied.close();
}

Axios: use an HTTPS proxy agent

Keep the request on Axios’s Node HTTP adapter when supplying httpsAgent. Set proxy: false to let that agent own the proxy connection. Use an Axios timeout and close the agent when the script exits.

// axios-check.mjs
import axios from 'axios';
import { isIP } from 'node:net';
import { checkServerIdentity } from 'node:tls';
import { HttpsProxyAgent } from 'https-proxy-agent';

const proxy = new URL(process.env.MAZE_PROXY_URL);
const host = proxy.hostname.replace(/^\[|\]$/g, '');
const options = proxy.protocol === 'https:' && isIP(host)
  ? { servername: 'proxy.invalid',
      checkServerIdentity: (_name, cert) => checkServerIdentity(host, cert) }
  : {};
const httpsAgent = new HttpsProxyAgent(proxy, options);
try {
  const { data } = await axios.get('https://api.ipify.org', {
    adapter: 'http', httpsAgent, proxy: false, timeout: 15_000,
  });
  console.log(String(data).trim());
} finally {
  httpsAgent.destroy();
}

Verify from the runtime that will make the real request

In a November 24, 2026 test with Node.js 26.13.0, direct fetch returned the machine’s IPv4. Fetch through Undici and Axios through the HTTPS proxy agent both returned the QA server’s IPv4.

  1. Run both files from the Node environment that sends the allowlisted requests.
    node fetch-check.mjs
    node axios-check.mjs
    You should see: The direct check shows your machine’s IP. Both proxied checks show your proxy server’s IP.

Official references

Skip the setup

A dedicated IPv4 in 38 cities, usually ready about 3 minutes after payment. Connect devices with WireGuard and apps with an authenticated HTTPS, HTTP, or SOCKS5 proxy. From $9.99/month.

FAQ

Questions, answered.

Something else? Open a ticket, a human replies.

Can I use the same dispatcher for several requests? +

Yes. Reuse it for the life of the client, and close it during shutdown.

What does the placeholder server name do? +

It supplies a DNS-shaped TLS server name while certificate identity is still checked against the actual proxy IP.

Do I need to set global proxy variables? +

These examples pass agents explicitly. A per-request agent makes the intended route clear.

What if these snippets produce a certificate error? +

Verify the proxy URL and the certificate’s identity and trust chain. Keep TLS verification enabled.

What does MazeVPN cost for this? +

Solo is $9.99 a month with one dedicated IPv4 and three proxy users. See the pricing page.

More guides