Skip to content

Configure TrueProxies with Node.js

axios’ built-in proxy option does not tunnel HTTPS requests through CONNECT reliably. Pass an agent instead, and set proxy: false so axios does not also apply its own proxy handling or HTTP_PROXY from the environment.

import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';
const agent = new HttpsProxyAgent(
'http://your_username:your_password@YOUR_HOST:YOUR_HTTP_PORT'
);
const response = await axios.get('https://httpbin.org/ip', {
httpsAgent: agent,
proxy: false,
});
console.log(response.data);
import fetch from 'node-fetch';
import { HttpsProxyAgent } from 'https-proxy-agent';
const agent = new HttpsProxyAgent(
'http://your_username:your_password@YOUR_HOST:YOUR_HTTP_PORT'
);
const response = await fetch('https://httpbin.org/ip', { agent });
const data = await response.json();
console.log(data);
import { ProxyAgent } from 'undici';
const proxyAgent = new ProxyAgent(
'http://your_username:your_password@YOUR_HOST:YOUR_HTTP_PORT'
);
const response = await fetch('https://httpbin.org/ip', {
dispatcher: proxyAgent,
});
const data = await response.json();
console.log(data);
import axios from 'axios';
import { SocksProxyAgent } from 'socks-proxy-agent';
const agent = new SocksProxyAgent(
'socks5h://your_username:your_password@YOUR_HOST:YOUR_SOCKS_PORT'
);
const response = await axios.get('https://httpbin.org/ip', {
httpsAgent: agent,
proxy: false,
});
console.log(response.data);

Append -country-XX to your username:

const agent = new HttpsProxyAgent(
'http://your_username-country-us:your_password@YOUR_HOST:YOUR_HTTP_PORT'
);
const agent = new HttpsProxyAgent(
'http://your_username-session-abc123:your_password@YOUR_HOST:YOUR_HTTP_PORT'
);