Skip to content
Esc

Articles

What is a proxy? A plain-English guide for beginners: how it works, the types, and what it's forWhat is a 4G proxy? How mobile proxies work, pros, cons and when to use oneRotating proxies explained: rotation types and how to change a proxy IP with a linkSOCKS5 vs HTTP proxies: what's the difference and which should you use?Proxy vs VPN: what's the difference, and when should you use each?Static vs rotating proxies: how they differ, pros and cons, and when to use eachDedicated vs shared proxies: how they differ, and what "dedicated" means for a 4G proxyIPv4 vs IPv6 proxies: how they differ, why IPv6 proxies are cheap, and when they don't workHow do websites detect proxies? 8 signals anti-bot systems look atProxy glossary A to Z: 35 terms you'll meet when buying and using proxies, explained simplyProxy vs antidetect browser: how they differ, and do you need a proxy if you have antidetect?What is a residential proxy? How it works, pros and cons, and when to use oneWhat is a datacenter proxy? Pros and cons, why it's cheap, and when it's still the right choiceHow to find your IP address on a computer or phone: public IP, local IP, and your IP behind a proxyWhy do you keep getting CAPTCHAs? 9 common triggers, and where your IP fits inreCAPTCHA vs hCaptcha vs Cloudflare Turnstile: how each one decides who gets challengedWhat is botting? Good bots, bad bots, and where your own automation fitsHow to get a Singapore IP address: VPN, proxy, cloud server or SIM, and how to check itProxies for Facebook: managing several accounts more reliably with 4G IPsProxies for TikTok and TikTok Shop: when you need a Singapore IP and how to use it properlyProxies for advertising: checking and managing ads aimed at SingaporeProxies for e-commerce sellers: see marketplaces like a buyer, track competitors, keep store logins steadyProxies for web scraping: which type to choose, how to rotate, and how to play fairDo you need a proxy to buy tickets on ThaiTicketMajor, Ticketmelon or SISTIC?Scraping Google and Bing search results with a proxy, and when to use the API insteadHow to scrape without getting blocked: pace, sessions and clean IPsProxies for price monitoring: tracking competitor and retail prices across regionsScraping anti-bot and anti-proxy websites (Cloudflare, Akamai, DataDome): what works, and the limitsIs web scraping legal? Robots.txt, terms, personal data and copyright (Vietnam, Singapore and beyond)What are 4G proxies used for? 10 jobs mobile proxies do well, and the ones to avoid4G proxies for testing apps and websites as a Singapore mobile user: QA, ads, payments, bot rulesProxies for Instagram: managing brand and client accounts steadily with 4G IPsUsing a proxy to check flight and hotel prices as a Singapore user: when it helps and what to knowResearching the Singapore market with a proxy: see search, ads, marketplaces and competitors as a local userProxies for LinkedIn: managing B2B accounts and reaching the Singapore market the right wayProxies for X (Twitter): managing brand and client accounts steadily and within the rulesProxies for airdrops: why farming wallets through proxies gets disqualified, and how to join airdrops safelyProxies for seeding, bought likes and fake reviews: why they get caught, the risks, and lasting ways to growProxies for flash sales and limited drops: what a proxy can and can't do, and how to shop sales properlyProxies for large-scale, multi-country scraping: choosing proxy types, system design and real costsProxies for Netflix, YouTube and foreign streaming: why they usually fail, cost a lot, and what to do insteadSelling to Singapore from Vietnam: choosing channels, GST, shipping, payments and the tools you needSelling on TikTok Shop Singapore from abroad: seller requirements, workable routes and what a proxy can doThe Singapore online shopping market: who shops, where, how they pay and the big sale seasonsA workflow for agencies managing client accounts with proxies and antidetect: inventory, access, offboardingLocal SEO in Singapore: checking Google and Google Maps rankings as a Singapore user, the right wayProxies for Google Ads: when you need one, the official tools to use first, and the policy lines to knowRoblox lagging, high ping: does a proxy help, and the fixes that really reduce Roblox lagMultiple Roblox accounts (alts): what the rules allow and forbid, whether you need a proxy, and IP bansLag and high ping on Singapore game servers: do proxies or VPNs lower ping, and what actually helpsDiscord proxy: what it can and can't do, how to set it up, and managing communities the right wayShopee and Lazada Singapore proxies: see what Singapore buyers see, run your shop, track competitorsProxies for online business (MMO): which jobs need one, which type to pick and what to avoidProxy for bots and automation: one identity per IP, a polite pace, and what to do when a CAPTCHA appearsHow to set up a proxy on Windows, macOS, iPhone and Android (with a username and password)How to add a proxy to GoLogin, AdsPower, Hidemyacc, GenLogin and MultiloginRotate a proxy IP automatically with an API: curl, Python and Node.js examplesHow to check a proxy: IP, country, carrier, speed and DNS and WebRTC leaksCommon proxy errors and how to fix them: 407, timeouts, ERR_PROXY_CONNECTION_FAILEDScraping JavaScript-rendered sites with a headless browser and a proxy403, 429 and 503 errors when scraping: causes and how to handle them properly (with Python code)Using a proxy with Scrapy: authenticated setup, polite throttling, error fixes and rotating between runsUsing a proxy with curl and wget: HTTP, SOCKS5, authentication, environment variables and debuggingUsing a proxy in Python: requests, httpx and aiohttp with HTTP, SOCKS5 and authenticationSetting up a proxy in Chrome and Edge: a browser-only proxy without changing the whole computerSingapore proxy for Telegram: set up SOCKS5 on desktop, iPhone and Android, and how it differs from MTProtoSlow 4G proxy? How to measure speed and latency properly, and what really makes a proxy fasterUsing proxies safely: protect your proxy password, rotation link, accounts and dataUsing Proxifier for software without proxy support: SOCKS5 setup, per-app rules and DNSRoblox proxies for developers: calling Roblox APIs from HttpService, Open Cloud, and a safe self-hosted relayProtecting your Roblox account: cookie theft, "free Robux", malicious extensions, and how to stay safeHow to set up a proxy in AdsPower: HTTP or SOCKS5, where to paste it, checking the Singapore IP and rotatingHow to add a proxy to GoLogin: HTTP or SOCKS5, where to enter it, checking the Singapore IP and rotatingHow to add a proxy to GenLogin: HTTP or SOCKS5, where to paste it, checking the Singapore IP and rotatingHow to add a proxy to Hidemium: HTTP or SOCKS5, where to enter it, checking the Singapore IP and rotatingHow to add a proxy to BitBrowser: HTTP or SOCKS5, where to enter it, checking the Singapore IP and rotatingCAPTCHA keeps appearing or loops forever: 8 fixes, in the order to try themProxy keeps disconnecting? Why 4G proxies drop connections and how to handle itPlaywright proxy: set up an authenticated proxy in Python and Node.jsPuppeteer proxy: --proxy-server, page.authenticate and a proxy per browser contextUsing a proxy in Node.js: fetch, axios, got and SOCKS5 with a username and passwordMobile vs residential vs datacenter proxies: comparing 4G, home and server IPs, and how to chooseSingapore proxies: when you need a Singapore IP and which type to chooseClean proxies and blacklists: what a clean IP means, and why "never blocked" is a myth4G rotating proxies: how mobile IP rotation works, what clean rotation means and how to choose oneHow to tell a real 4G proxy from a fake: check the carrier, IP type, latency and rotationFree vs paid proxies: the real risks of free proxies, and when paying is worth itDedicated 4G proxies, not shared: why a proxy only you use matters, and how to check it yourselfHow many proxies do I need? Working out the number for accounts, teams and scrapingStatic IP proxies for allowlists, APIs and remote access: 5 options and how to choose the right oneVietnam or Singapore proxy? Choosing which country's IP fits your workSingtel, M1 and StarHub proxies: which Singapore carrier a 4G proxy runs on, and how to check itClean proxy and CAPTCHA: how IP reputation decides how many challenges you seeThe real cost of a dirty proxy: CAPTCHAs, retries, wasted bandwidth and blocked accountsSingapore SOCKS5 proxy: when to use it, how to set it up, and how to check it5G proxy vs 4G proxy: what changes, what doesn't, and whether 5G is worth paying more forCheap 4G proxies: $4 gets you 200GB, and how to compare mobile proxy prices properly before you buyRefer a friend and earn 10% on every proxy order: how the 65Proxy referral program worksWhy choose 65Proxy? 8 reasons you can verify, and when you should go elsewhereHow to buy a 4G proxy at 65Proxy: sign up, top up, pay, connect and rotate, step by stepWhere to buy a reliable proxy? 12 things to check before paying any providerTesting a 4G proxy in a 1-hour trial: a minute-by-minute checklistBuy proxies with USDT: paying for a Singapore 4G proxy over TRC20 or BEP20, step by step4G proxy with 500GB: what the plan includes, how far 500GB goes, and how bandwidth is countedGuides to 4G mobile proxies

Using a proxy in Node.js: fetch, axios, got and SOCKS5 with a username and password

Setup and use 6 min read

In this article
  1. 01 Which method should you use?
  2. 02 fetch with undici
  3. 03 Without packages: NODE_USE_ENV_PROXY
  4. 04 axios
  5. 05 got
  6. 06 SOCKS5 with socks-proxy-agent
  7. 07 Timeouts and retries
  8. 08 Common errors
  9. 09 Node.js with 65Proxy's Singapore 4G proxies
  10. 10 Frequently asked questions

Node.js doesn't send requests through a proxy unless you tell it to. The simplest way today is undici's ProxyAgent with undici's own fetch, which reads the username and password straight from a URL like http://USER:PASS@HOST:PORT. axios has its own proxy option, got takes proxy agents, and SOCKS5 works through socks-proxy-agent. Every example below was tested on 18 November 2026 with Node.js 24 against a test proxy that requires a password.

Which method should you use?

You use Install Notes
fetch undici Import fetch and ProxyAgent from undici together
No extra package Nothing NODE_USE_ENV_PROXY=1, still experimental
axios axios proxy option; HTTPS sites need axios 1.16.1 or newer
got got, hpagent got 16 is ESM-only and needs Node 22
SOCKS5 port socks-proxy-agent Use socks5h:// so the proxy resolves names

Each example reads the proxy from a PROXY environment variable, so the password stays out of your code. Save the files with the .mjs extension to use import.

fetch with undici

Install with npm install undici:

JavaScript
import { fetch, ProxyAgent } from "undici";

const proxy = new ProxyAgent(process.env.PROXY); // http://USER:PASS@HOST:PORT

const res = await fetch("https://65proxy.com/ip.json", { dispatcher: proxy });
console.log(await res.json());

The result shows the IP the site sees and its country (SG for a Singapore proxy). Two things to get right:

  • Import fetch from undici too. Passing undici 8's ProxyAgent to Node 24's built-in fetch fails with TypeError: fetch failed, because the two undici versions don't match.
  • Encode special characters in the password: @ becomes %40, : becomes %3A. encodeURIComponent(password) does it for you.

To send every fetch call in the program through the proxy, including the built-in one, set a global dispatcher once:

JavaScript
import { ProxyAgent, setGlobalDispatcher } from "undici";

setGlobalDispatcher(new ProxyAgent(process.env.PROXY));

const res = await fetch("https://65proxy.com/ip.json"); // Node's built-in fetch
console.log(await res.json());

Without packages: NODE_USE_ENV_PROXY

Recent Node.js versions can read the usual proxy variables themselves when you turn it on:

Terminal
NODE_USE_ENV_PROXY=1 HTTP_PROXY="http://USER:PASS@HOST:PORT" HTTPS_PROXY="http://USER:PASS@HOST:PORT" node app.mjs

On Windows PowerShell, set $env:NODE_USE_ENV_PROXY = "1" and the two proxy variables before running node. What to know:

  • Versions: it covers fetch from Node 24.0 and also http and https from Node 24.5 (and 22.21). The --use-env-proxy flag does the same.
  • Status: the feature is still marked experimental in Node's documentation.
  • HTTP proxies only: don't put a SOCKS5 address in these variables.
  • NO_PROXY lists sites that should skip the proxy.

axios

axios has a proxy option with the login in its own auth field:

JavaScript
import axios from "axios";

const res = await axios.get("https://65proxy.com/ip.json", {
  proxy: {
    protocol: "http",
    host: process.env.PROXY_HOST,
    port: Number(process.env.PROXY_PORT),
    auth: { username: process.env.PROXY_USER, password: process.env.PROXY_PASS },
  },
  timeout: 30000,
});
console.log(res.data);

Check your axios version with npm ls axios. Before 1.16.1, axios sent requests for HTTPS sites to the proxy without opening a tunnel, and they failed. If you must stay on an older version, or want the same code for every client, use an agent and turn axios's own proxy handling off:

JavaScript
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";

const agent = new HttpsProxyAgent(process.env.PROXY);
const res = await axios.get("https://65proxy.com/ip.json", { httpsAgent: agent, proxy: false });
console.log(res.data);

Always set proxy: false when you pass your own agent.

got

got 16 recommends the hpagent package (npm install got hpagent). Give it one agent for HTTP sites and one for HTTPS sites:

JavaScript
import got from "got";
import { HttpProxyAgent, HttpsProxyAgent } from "hpagent";

const proxy = process.env.PROXY;
const data = await got("https://65proxy.com/ip.json", {
  agent: {
    http: new HttpProxyAgent({ proxy }),
    https: new HttpsProxyAgent({ proxy }),
  },
  timeout: { request: 30000 },
}).json();
console.log(data);

Careful: hpagent and https-proxy-agent both export a class named HttpsProxyAgent, but hpagent's takes an object ({ proxy }) while the other takes the URL directly.

SOCKS5 with socks-proxy-agent

To use the proxy's SOCKS5 port, install socks-proxy-agent and write the address with socks5h://, which makes the proxy look up site names itself:

JavaScript
import https from "node:https";

import { SocksProxyAgent } from "socks-proxy-agent";

const agent = new SocksProxyAgent(process.env.SOCKS_PROXY); // socks5h://USER:PASS@HOST:PORT

https.get("https://65proxy.com/ip.json", { agent }, (res) => {
  res.pipe(process.stdout);
});

The same agent works elsewhere:

  • axios: { httpAgent: agent, httpsAgent: agent, proxy: false }.
  • got: { agent: { http: agent, https: agent } }.

Why socks5h:// and not socks5://: with socks5://, your own machine resolves the name and may hand the proxy an IPv6 address, which an IPv4-only 4G line can't reach. The details are in proxy keeps disconnecting and socks5 or socks5h. undici also has a Socks5ProxyAgent, but it is still marked experimental.

Timeouts and retries

Mobile lines have slow moments and short drops, so give every request a timeout and retry the ones that fail on the connection. This helper waits 5, 10, 20 and 40 seconds between tries:

JavaScript
import { fetch, ProxyAgent } from "undici";

const proxy = new ProxyAgent(process.env.PROXY);
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

// undici wraps the real reason in err.cause, sometimes twice
function reason(err) {
  while (err.cause) err = err.cause;
  return err.message;
}

async function get(url, tries = 5) {
  for (let attempt = 1; attempt <= tries; attempt++) {
    try {
      const res = await fetch(url, { dispatcher: proxy, signal: AbortSignal.timeout(30000) });
      if (![502, 503, 504].includes(res.status)) return res;
      console.log("attempt", attempt, "got", res.status);
    } catch (err) {
      console.log("attempt", attempt, "failed:", reason(err));
    }
    if (attempt < tries) await sleep(5000 * 2 ** (attempt - 1));
  }
  throw new Error("The proxy is still failing; check the line or contact support");
}

const res = await get("https://65proxy.com/ip.json");
console.log(await res.json());

When to stop retrying and what to send support are in proxy keeps disconnecting. To change the IP from the same script, see rotating the IP with an API.

Common errors

With undici, every failure surfaces as TypeError: fetch failed; the real reason is inside err.cause, which the reason() helper above prints.

Error (innermost message) Cause Fix
invalid onRequestStart method Built-in fetch with a ProxyAgent from a different undici version Import fetch from undici, or use setGlobalDispatcher
Proxy response (407) !== 200 when HTTP Tunneling Wrong username or password, or unencoded special characters Copy the login again; see 407 errors
Proxy response (502) !== 200 when HTTP Tunneling The proxy can't reach the site, for example an IPv6-only address See tunnel errors
ECONNREFUSED Wrong host or port Check the address and port
ECONNRESET or socket hang up now and then An idle connection was closed, or the line dropped Retry, as in the code above
HTTPS sites fail only in axios axios older than 1.16.1 Upgrade, or use HttpsProxyAgent with proxy: false
ERR_REQUIRE_ESM require() on an ESM-only package such as got Use import in a .mjs file

When a script fails, try the same proxy with curl: if curl works, the problem is in the code. The curl commands are in using a proxy with curl.

Node.js with 65Proxy's Singapore 4G proxies

Every 65Proxy proxy has an HTTP port and a SOCKS5 port with one username and password, a rotation link, and a Singapore IP from the Singtel or M1 4G network. It is not shared with other customers.

  • Plans: 1 day $4, 7 days $13, 1 month $32, plus monthly plans with more bandwidth (500GB $40, 1TB $65).
  • Test your code first on the free 1-hour trial.
  • Buy: get a Singapore 4G proxy; it is delivered automatically once paid.

Need a browser rather than plain requests? See Puppeteer proxy setup or Playwright proxy setup.

Frequently asked questions

Does Node's fetch use HTTP_PROXY automatically?

Not by default. Node reads HTTP_PROXY and HTTPS_PROXY only when you set NODE_USE_ENV_PROXY=1 or pass --use-env-proxy, and the feature is still experimental.

Which client is fastest through a proxy?

The difference between clients is tiny next to the network itself. Pick the one your project already uses; what really affects speed is in proxy speed.

Can I use the SOCKS5 port with fetch?

undici's experimental Socks5ProxyAgent can do it. For production code, socks-proxy-agent with https, axios or got is the more established path, or simply use the HTTP port with ProxyAgent.

How do I use a different proxy per request?

Create one ProxyAgent per proxy and pass the right one as dispatcher on each fetch call. Reuse the agents instead of creating a new one for every request.