Node.js handles most scraping and automation tasks well out of the box, but the moment you need to route traffic through a proxy, things get a little more involved. Axios does not support proxies the same way a browser does, and using it correctly requires understanding how HTTP agents work under the hood. Getting this wrong means your proxy either does not work at all or leaks your real IP on HTTPS requests.
In this article, we'll explore how to configure Axios and HTTP agents in Node.js to route traffic through a proxy properly.
How Axios Proxy Configuration Works

Axios has a built-in proxy field, but it only works reliably for HTTP requests. You pass your proxy details directly into the request config, which accepts a host, port, and optional authentication object.
1const axios = require('axios');
2
3const response = await axios.get('http://example.com', {
4 proxy: {
5 host: 'your.proxy.host',
6 port: 8080,
7 auth: {
8 username: 'user',
9 password: 'pass'
10 }
11 }
12});
The problem starts with HTTPS. When the target URL is HTTPS, Axios does not tunnel the request correctly through the proxy. The proxy ends up seeing the full request in plain text instead of establishing a proper CONNECT tunnel, which defeats the purpose entirely. For HTTPS targets, you need an HTTP agent instead.
Also Read: Datacenter Proxies for Web Scraping
Using HTTP Agents for HTTPS Requests

To route HTTPS traffic correctly, you need the https-proxy-agent package. It creates an agent that properly handles the CONNECT tunnel, keeping your traffic encrypted end-to-end.
1npm install https-proxy-agent
Once installed, pass the agent into Axios through the httpsAgent field instead of the proxy field. The proxy URL is passed directly as a string, including credentials if your provider requires authentication.
1const axios = require('axios');
2const { HttpsProxyAgent } = require('https-proxy-agent');
3
4const agent = new HttpsProxyAgent('http://user:pass@your.proxy.host:8080');
5
6const response = await axios.get('https://example.com', {
7 httpsAgent: agent
8});
This is the correct approach for most scraping and automation use cases. Do not mix the proxy field and httpsAgent on the same request, or Axios will behave unpredictably.
Putting It All Together with Rotating Proxies

With a rotating proxy service like residential proxies, the setup stays the same. You get a single endpoint URL, and Proxyon handles IP rotation on its end, so every request goes out from a different IP without any extra logic on your end.
1const axios = require('axios');
2const { HttpsProxyAgent } = require('https-proxy-agent');
3
4async function scrape(url) {
5 const agent = new HttpsProxyAgent('http://user:pass@proxy.proxyon.io:8080');
6 const response = await axios.get(url, { httpsAgent: agent });
7 return response.data;
8}
Recreating the agent per request ensures each call gets a fresh IP. Residential proxies rotate automatically at the session level, so a new agent triggers a new IP assignment. Proxyon supports both HTTP and SOCKS5, works with any Node.js HTTP client, and starts at $1.75/GB with no subscription required. Deposit $5 and start at Proxyon.
Also Read: How to Scrape a JavaScript Website With Python
Final Thoughts
Axios's built-in proxy field works for HTTP but falls short on HTTPS. Pairing it with https-proxy-agent closes that gap and gives you a setup that handles both correctly. Add a rotating residential proxy like Proxyon on top, and you have a scraping stack that scales without getting blocked.




