Developers
Node.js proxies.
Undici (Node 18+ fetch) and axios both accept an HTTP or SOCKS5 proxy. Targeting stays in the username.
fetch / undici (Node 18+)
Pass a ProxyAgent. Keep credentials in env vars, not in the repo.
import { fetch, ProxyAgent } from "undici";
const agent = new ProxyAgent("http://USER-country-DE:PASS@GATEWAY:7777");
const res = await fetch("https://ip-api.com/json", { dispatcher: agent });
console.log(await res.json()); axios
axios uses a proxy object. For SOCKS5 use axios plus a socks-proxy-agent and port 1080.
import axios from "axios";
const { data } = await axios.get("https://ip-api.com/json", {
proxy: {
protocol: "http",
host: "GATEWAY",
port: 7777,
auth: { username: "USER-country-DE", password: "PASS" },
},
timeout: 20000,
});
console.log(data); FAQ
Does native fetch in Node honor HTTP_PROXY?
Not reliably. Use undici ProxyAgent or axios. Do not assume env-only proxying.
Agents and browsers?
Server-side Node is the right place for the gateway password. Do not embed it in frontend JS.