Install
Node.js 18 or newer. The second package pair is only for axios.
npm i undici
npm i axios https-proxy-agentRotating residential
An agent pools connections, and a pooled HTTPS tunnel keeps its exit IP. For a new residential address per request, give each request its own agent and close it afterwards.
import { fetch, ProxyAgent } from "undici";
for (let i = 0; i < 3; i++) {
const dispatcher = new ProxyAgent("http://USER:[email protected]:8000");
const res = await fetch("https://httpbin.org/ip", { dispatcher });
console.log((await res.json()).origin);
await dispatcher.close();
}A static datacenter or ISP IP
On a static datacenter IP, share one agent so connections are reused. This is the axios version. For an ISP order, use the host and port from your dashboard.
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
const agent = new HttpsProxyAgent("http://USER:PASS@IP:PORT");
const { data } = await axios.get("https://httpbin.org/ip", {
httpsAgent: agent,
proxy: false,
timeout: 30000,
});
console.log(data.origin);Keeping one identity
Reusing one agent keeps traffic on a few tunnels, which on the rotating gateway means a few addresses. That is a cheap way to hold an address for a short burst. For an address that holds across new connections, residential supports sticky sessions; the session setting for your account is in the dashboard. Bot libraries take the same agents: discord.js passes an undici ProxyAgent to its REST calls and Telegraf takes an HttpsProxyAgent, as Discord bots with discord.js and Telegram bots with Telegraf show. If the calls live in an n8n workflow rather than a script, the n8n proxy guide puts the proxy on the HTTP Request node.