Magkaiba ang paghawak ng bawat Node.js HTTP client sa proxy, at kalahati sa kanila ay hindi man lang humahawak ng proxy authentication nang walang helper package. Tahimik na hindi pinapansin ng axios ang sarili nitong proxy option para sa mga HTTPS target sa ilang bersyon, ang native fetch ay walang anumang proxy option, at ang mga error message — ECONNRESET, 407, o basta nag-ha-hang lang — ay walang sinasabi sa iyo.
Ito ang kumpleto at gumaganang reference para sa pag-ruta ng axios, got, node-fetch, native fetch (undici), at superagent sa pamamagitan ng authenticated residential proxies. Ito ang katuwang sa Node ng aming mga gabay sa Python (requests/httpx/aiohttp, Scrapy). Lahat ng halimbawa ay gumagamit ng standard na placeholder format — palitan ng tunay mong credentials:
socks5h://USERNAME:[email protected]:913
Huwag gamitin ang built-in na proxy options. Gumamit ng proxy agent. Ini-delegate ng mga HTTP client ng Node ang paghawak ng connection sa isang "agent" object, at ang mga agent package (https-proxy-agent, socks-proxy-agent) ay tama ang pag-implementa ng CONNECT tunneling at authentication. Ang built-in na options ay madalas na hindi — ang proxy config ng axios ang pinaka-kilalang halimbawa.
npm install socks-proxy-agent https-proxy-agent
const axios = require("axios");
const { SocksProxyAgent } = require("socks-proxy-agent");
const agent = new SocksProxyAgent(
"socks5h://USERNAME:[email protected]:913"
);
const res = await axios.get("https://api.ipify.org?format=json", {
httpAgent: agent, // for http:// targets
httpsAgent: agent, // for https:// targets
proxy: false, // IMPORTANT: disable axios's own proxy handling
});
console.log(res.data); // -> the proxy's exit IP
Dalawang bagay na nakakaligtaan ng mga tao: kailangan mong i-set ang parehong httpAgent at httpsAgent (pumipili ang axios ayon sa target scheme), at kailangan mong i-set ang proxy: false para hindi rin subukan ng axios na i-apply ang HTTP_PROXY environment variables sa ibabaw ng iyong agent.
const got = require("got");
const { SocksProxyAgent } = require("socks-proxy-agent");
const agent = new SocksProxyAgent(
"socks5h://USERNAME:[email protected]:913"
);
const body = await got("https://api.ipify.org?format=json", {
agent: { http: agent, https: agent },
}).json();
Kung nag-i-scrape ka ng mga protektadong target gamit ang got, tingnan ang got-scraping sa halip — parehong API, kasama ang browser-like header generation at HTTP/2 fingerprint mimicry (kung bakit ito mahalaga: JA3/JA4 explained).
Ang built-in na fetch ng Node ay galing sa undici, hindi pinapansin ang proxy environment variables, at walang agent option. Ang paraan ng undici ay isang dispatcher:
const { ProxyAgent } = require("undici");
// undici's ProxyAgent speaks HTTP CONNECT (use your HTTP proxy port)
const dispatcher = new ProxyAgent({
uri: "http://us.jibaoproxy.com:1000",
token: "Basic " + Buffer.from("USERNAME:PASSWORD").toString("base64"),
});
const res = await fetch("https://api.ipify.org?format=json", { dispatcher });
console.log(await res.json());
Tandaan: ang ProxyAgent ng undici ay HTTP-proxy lamang. Para sa SOCKS5 gamit ang native fetch, alinman sa lagyan mo ito ng local forwarder sa harap o gumamit ng client na tumatanggap ng socks agents (axios/got sa itaas).
const fetch = require("node-fetch");
const { SocksProxyAgent } = require("socks-proxy-agent");
const agent = new SocksProxyAgent(
"socks5h://USERNAME:[email protected]:913"
);
const res = await fetch("https://api.ipify.org?format=json", { agent });
Sa isang rotating residential gateway hindi mo kailangang mag-manage ng IP lists — binibigyan ka ng gateway ng sariwang exit bawat connection, o humahawak ng isang exit bawat session id. Sa Node ito ay malinis na nai-map sa isang agent bawat identity:
// Sticky: same session id -> same exit IP across requests
function identityAgent(sessionId) {
return new SocksProxyAgent(
`socks5h://USERNAME-session-${sessionId}:[email protected]:913`
);
}
// Account A keeps IP A, account B keeps IP B - cookies and IP move together
const agentA = identityAgent("acct_a");
const agentB = identityAgent("acct_b");
Gamitin ulit ang agent para sa connection pooling sa loob ng isang identity; huwag kailanman magbahagi ng isang agent sa iba't ibang identity. Kung kailan mag-rotate vs mag-stick ay sariling paksa — tingnan ang sticky vs rotating sessions.
| Sintomas | Sanhi | Solusyon |
|---|---|---|
407 Proxy Authentication Required | Hindi nakarating ang credentials sa proxy | Ilagay ang user:pass sa agent URL, hindi sa client config |
| Gumagana ang axios sa http://, nabibigo sa https:// | httpAgent lang ang naka-set | I-set din ang httpsAgent, at proxy: false |
ECONNRESET agad-agad | Maling port / maling protocol (HTTP port na may SOCKS agent) | Itugma ang agent type sa port |
| Nag-le-leak ang DNS / nabibigo ang internal hostnames | Ang socks5:// ay nire-resolve ang DNS nang lokal | Gamitin ang socks5h:// — ipinapadala ng h ang hostnames sa proxy |
| Hindi pinapansin ng native fetch ang HTTP_PROXY | Hindi binabasa ng undici ang env vars | Magpasa ng dispatcher nang malinaw |
| Gumagana nang lokal, 403 sa target site | Hindi proxy bug — TLS fingerprint | got-scraping o tunay na browser; tingnan ang TLS guide |
socks-proxy-agent / https-proxy-agent); huwag kailanman magtiwala sa built-in na proxy options.proxy: false. got: agent: {http, https}. Native fetch: undici ProxyAgent dispatcher.socks5h:// para nire-resolve ang DNS sa pamamagitan ng proxy — walang leaks.SOCKS5 + HTTP endpoints, sticky o rotating, per-GB pricing — 500MB ng libreng traffic, walang card kailangan.
Simulan ang Libreng TrialAng mga bagong user ay makakatanggap ng 500MB sa pagrehistro, kasama ang bonus sa unang recharge. Limitadong oras lang ang alok.