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
- Open IP addresses in your Prontaro dashboard (my.prontaro.com/ips) and select your dedicated IPv4.
- Copy the
HTTPSproxy URL (:443) from Proxy credentials.
Export the proxy string to PRONTARO_PROXY_URL:
export PRONTARO_PROXY_URL="https://user:pass@<entry>.prontaro.io:443"undici (ProxyAgent) — recommended
Install undici and create one module-level ProxyAgent so requests share a single TCP/TLS keep-alive pool:
npm install undici// 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.10After 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:
npm install axios https-proxy-agent// 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):
// 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());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.mjsBecause 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:
npm install axios socks-proxy-agent// 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
fetchwith npmundici’sProxyAgent. Version mismatches between Node’s bundled undici and the installed package can breakdispatcher. Import bothfetchandProxyAgentfrom'undici'. - Omitting
proxy: falseinaxios. WhenHTTPS_PROXYis set alongsidehttpsAgent, Axios tries to proxy the request twice. - Passing
SocksProxyAgenttofetch({ dispatcher }).SocksProxyAgentimplements Node’shttp.Agent, notundici.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:
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
- curl and environment variables — diagnose
407and403errors withcurl -v. - HTTP & SOCKS5 proxy — configure
accessandtargetsallowlists and credential rotation. - Static IP for Vercel — configure proxy and Relay URLs in Vercel Functions.
- Static IP for AWS Lambda — use a static IP without VPC plumbing or a NAT Gateway.
Something wrong on this page? Contact us