How to set up a proxy in Node.js (Axios & Native Fetch)
Updated:
Axios's built-in proxy: { host, port } option fails on https:// targets because it does not issue an HTTP CONNECT tunnel. To route Node.js and TypeScript requests cleanly through VinaProxy authenticated HTTP(S) proxies, pass an HttpsProxyAgent (https-proxy-agent) to Axios or an undici.ProxyAgent dispatcher to native Node fetch().
new HttpsProxyAgent('http://user:pass@ip:port')- 1 IP₫40,000
- 5+ IPs₫35,000
- 10+ IPs₫25,000
- 20+ IPs₫25,000
- 50+ IPs₫25,000
- 100+ IPs₫25,000
- 200+ IPs₫25,000
- 500+ IPs₫25,000
- 1000+ IPs₫22,000
- 2000+ IPs₫20,000
- 1 IP₫40,000
- 5+ IPs₫35,000
- 10+ IPs₫25,000
- 20+ IPs₫25,000
- 50+ IPs₫25,000
- 100+ IPs₫25,000
- 200+ IPs₫25,000
- 500+ IPs₫25,000
- 1000+ IPs₫22,000
- 2000+ IPs₫20,000
Axios vs. Native Node.js fetch() proxy configuration
Both libraries accept standard http://user:pass@ip:port URLs from your VinaProxy dashboard:
| HTTP Client | Package | Recommended Code Snippet |
|---|---|---|
| Axios | npm i https-proxy-agent | axios.get(url, { httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port'), proxy: false }) |
Native fetch (Node 18+) | npm i undici | fetch(url, { dispatcher: new ProxyAgent('http://user:pass@ip:port') }) |
| Got | npm i hpagent | got(url, { agent: { https: new HttpsProxyAgent({ proxy: 'http://user:pass@ip:port' }) } }) |
Connection pooling & timeout best practices in Node.js
- Always set
proxy: falsealongsidehttpsAgentin Axios so Axios ignores conflicting systemHTTP_PROXYenvironment variables - Instantiate
HttpsProxyAgentorProxyAgentonce per proxy IP outside your loop to reuse persistent keep-alive sockets - Export your VinaProxy proxy list directly as a JSON array using our Proxy Format Converter
Step by step
- 1
Install https-proxy-agent (or undici)
Run
npm install axios https-proxy-agentin your Node.js project. - 2
Create the HttpsProxyAgent instance
Initialize
const agent = new HttpsProxyAgent('http://user:pass@ip:port');using your VinaProxy credentials. - 3
Pass httpsAgent and proxy: false to Axios
Call
const res = await axios.get('https://vinaproxy.com/api/my-ip', { httpsAgent: agent, proxy: false, timeout: 10000 });. - 4
Verify the exit IP
Log
res.datato confirm the response came through your dedicated proxy IP.
Frequently asked questions
Why does Axios's default `proxy: { host, port, auth }` fail on HTTPS URLs?
Axios's built-in proxy config sends a plain HTTP request instead of opening an HTTP CONNECT TLS tunnel. Using httpsAgent: new HttpsProxyAgent('http://user:pass@ip:port') with proxy: false fixes this.
How do I use a proxy with native `fetch()` in Node.js 18/20/22?
Import ProxyAgent from undici and pass { dispatcher: new ProxyAgent('http://user:pass@ip:port') } in the fetch() options object.
Can I convert my proxy list to JSON for Node.js?
Yes—paste your ip:port:user:pass lines into our free Proxy Format Converter and select JSON output.
Power your Node.js backends & scrapers with static IPs
Instant unmetered Dedicated IPv4 and Static ISP proxies across 7 countries.
Buy Node.js Proxies