Install
Node.js 18 or newer. The examples are ES modules, so save them as .mjs files.
npm i axios https-proxy-agentRotating residential
An agent with keep-alive off opens a new CONNECT tunnel for every request, and each new tunnel through the residential gateway leaves from a new address. proxy: false stops Axios applying its own proxy handling, including any https_proxy in the environment, on top of the agent.
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
const client = axios.create({
httpsAgent: new HttpsProxyAgent("http://USER:[email protected]:8000", { keepAlive: false }),
proxy: false,
timeout: 30000,
});
for (let i = 0; i < 3; i++) {
const { data } = await client.get("https://httpbin.org/ip");
console.log(data.origin);
}A static datacenter or ISP IP
On a static datacenter IP, turn keep-alive on so requests reuse a tunnel, and cap the sockets the agent may open. For an ISP order, use the host and port from your dashboard.
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
const client = axios.create({
httpsAgent: new HttpsProxyAgent("http://USER:PASS@IP:PORT", { keepAlive: true, maxSockets: 8 }),
proxy: false,
timeout: 30000,
});
for (const url of ["https://httpbin.org/ip", "https://httpbin.org/headers"]) {
const res = await client.get(url);
console.log(res.status, JSON.stringify(res.data).slice(0, 80));
}Keeping one identity
Axios keeps no connection state of its own; the agent does. With keepAlive: true, sequential requests to one host reuse a tunnel and keep its address while the socket stays open, which covers a short burst. Axios in Node also keeps no cookies, so a login flow needs a cookie jar and a stable address: a static IP, or a residential sticky session whose setting for your account is in the dashboard.