Skip to content
Sections

Node.js and TypeScript

Route Node.js and TypeScript requests through your dedicated static IPv4 with undici, axios, native fetch, or SOCKS5 with connection pooling.

On this page8

The right client depends on the proxy protocol and your Node.js runtime — pick the pattern that matches your stack:

Client Proxy schemes Best for
undici (ProxyAgent) https://, http:// Default choice for Node 20+ servers and serverless functions using fetch
axios + https-proxy-agent https://, http:// Existing axios codebases
Native fetch + NODE_USE_ENV_PROXY=1 https://, http:// Zero dependencies on Node 22.21+ and Node 24+
socks-proxy-agent socks5h:// node:https or axios clients that need SOCKS5

Step 1. Get your proxy URL

  1. Open IP addresses in your Prontaro dashboard (my.prontaro.com/ips) and select your dedicated IPv4.
  2. Copy the HTTPS proxy URL (:443) from Proxy credentials.
IP addressesProxy credentialsOpen in dashboard

Export the proxy string to PRONTARO_PROXY_URL:

bash
export PRONTARO_PROXY_URL="https://user:pass@<entry>.prontaro.io:443"

Install undici and create one module-level ProxyAgent so requests share a single TCP/TLS keep-alive pool:

bash
npm install undici
ts
// egress-client.ts
import { fetch, ProxyAgent } from 'undici';

const proxyUrl = process.env.PRONTARO_PROXY_URL;
if (!proxyUrl) {
  throw new Error('PRONTARO_PROXY_URL is not set');
}

// One shared agent per process — do not close it after every request
export const proxyAgent = new ProxyAgent({
  uri: proxyUrl,
  connections: 10,
});

export async function checkOutboundIp(): Promise<string> {
  const res = await fetch('https://api.ipify.org', {
    dispatcher: proxyAgent,
    signal: AbortSignal.timeout(15_000),
  });

  if (!res.ok) {
    throw new Error(`HTTP ${res.status}: ${await res.text()}`);
  }
  return (await res.text()).trim();
}

// Close only during graceful process shutdown
process.once('SIGTERM', () => {
  void proxyAgent.close();
});

console.log(await checkOutboundIp());

Verify your outbound IP:

npx tsx egress-client.ts
203.0.113.10

After confirming api.ipify.org returns your dedicated IPv4, you can lock down destinations in the dashboard (IP addresses → Proxy credentials → Access).

axios + https-proxy-agent

Axios’s built-in proxy option struggles with https:// proxy hosts and can conflict with environment variables. Pass HttpsProxyAgent as httpsAgent and explicitly set proxy: false:

bash
npm install axios https-proxy-agent
ts
// axios-client.ts
import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';

const proxyUrl = process.env.PRONTARO_PROXY_URL;
if (!proxyUrl) {
  throw new Error('PRONTARO_PROXY_URL is not set');
}

const httpsAgent = new HttpsProxyAgent(proxyUrl);

export const partnerApi = axios.create({
  httpsAgent,
  proxy: false, // disable Axios's built-in HTTP_PROXY handling
  timeout: 15_000,
});

const { data } = await partnerApi.get<string>('https://api.ipify.org');
console.log(data.trim());

Native fetch with NODE_USE_ENV_PROXY=1 (Node 22 / 24)

In Node.js 24+ and Node.js 22.21+, built-in fetch() honors HTTPS_PROXY, HTTP_PROXY, and NO_PROXY with zero dependencies when started with NODE_USE_ENV_PROXY=1 (or --use-env-proxy):

js
// check-env.mjs
const res = await fetch('https://api.ipify.org', {
  signal: AbortSignal.timeout(15_000),
});
if (!res.ok) {
  throw new Error(`HTTP ${res.status}`);
}
console.log((await res.text()).trim());
bash
HTTPS_PROXY="$PRONTARO_PROXY_URL" \
NO_PROXY="localhost,127.0.0.1,::1,169.254.169.254,.internal" \
NODE_USE_ENV_PROXY=1 \
node check-env.mjs

Because this applies to every fetch() call in the process, always configure NO_PROXY so internal services and telemetry bypass Prontaro.

SOCKS5 (socks5h://) with socks-proxy-agent

undici.ProxyAgent supports http:// and https:// only. For socks5h:// (:1080), pair SocksProxyAgent with axios or node:https:

bash
npm install axios socks-proxy-agent
ts
// socks-client.ts
import axios from 'axios';
import { SocksProxyAgent } from 'socks-proxy-agent';

// Use socks5h:// so DNS resolves on the Prontaro node
const socksUrl = process.env.PRONTARO_SOCKS_URL; // socks5h://user:pass@<entry>.prontaro.io:1080
if (!socksUrl) {
  throw new Error('PRONTARO_SOCKS_URL is not set');
}

const socksAgent = new SocksProxyAgent(socksUrl);

const { data } = await axios.get<string>('https://api.ipify.org', {
  httpAgent: socksAgent,
  httpsAgent: socksAgent,
  proxy: false,
  timeout: 15_000,
});
console.log(data.trim());

Common Node.js issues

  • Mixing global fetch with npm undici’s ProxyAgent. Version mismatches between Node’s bundled undici and the installed package can break dispatcher. Import both fetch and ProxyAgent from 'undici'.
  • Omitting proxy: false in axios. When HTTPS_PROXY is set alongside httpsAgent, Axios tries to proxy the request twice.
  • Passing SocksProxyAgent to fetch({ dispatcher }). SocksProxyAgent implements Node’s http.Agent, not undici.Dispatcher.
  • Allocating a new agent per request. Calling new ProxyAgent(...) in a route handler forces a new proxy TLS handshake every time and can hit per-IP concurrent connection limits.

Calling an API through a Relay URL

In edge runtimes or codebases where you cannot configure a proxy agent, create a Relay in the dashboard (IP addresses) and call it directly with fetch:

ts
const res = await fetch(`${process.env.PRONTARO_RELAY_URL}/v1/status`, {
  headers: {
    Authorization: `Bearer ${process.env.PARTNER_API_TOKEN}`,
    // Include only if you set a password (in the dashboard under IP addresses → Relay address → Access):
    'Prontaro-Relay-Auth': `${process.env.RELAY_LOGIN}:${process.env.RELAY_PASSWORD}`,
  },
  signal: AbortSignal.timeout(15_000),
});
if (!res.ok) {
  throw new Error(`HTTP ${res.status}: ${await res.text()}`);
}
console.log(await res.json());

See Relay URLs for TLS termination details and limits.

Next steps

Something wrong on this page? Contact us

Contact us

Enter your email so we can reply.Enter a valid email, e.g. name@company.example.
Tell us what you need or what went wrong.up to 2,000 characters

Sent! We’ll reply to .

Or email us at support@prontaro.com