Axios proxy configuration helps Node.js developers, web scrapers, and automation teams route requests securely while improving privacy and reliability. In this blog, we’ll show you how to set up an Axios proxy, configure authentication, use rotating proxies, and handle common connection failures.
Whether you need to scrape websites, access geo-restricted content, or hide your real IP address, these techniques can help keep your requests efficient, stable, and less likely to be blocked.

Quick Axios Proxy Setup
Setting up an Axios proxy in Node.js is straightforward once you have a working proxy server and valid credentials. If you are new to proxy networking, reviewing a general Set Up process can help you understand the key requirements before configuring Axios.
With just a few configuration settings, you can route requests through a proxy to improve privacy, access location-specific content, and manage traffic more effectively.
Install Axios
Before configuring an Axios proxy, create a Node.js project and install Axios.
npm init -y
npm install axios
Axios is a popular HTTP client that supports proxy configuration for server-side applications. Following proven Setup & Integration practices can make deployment easier and reduce configuration issues as your project grows.
Configure a Basic Proxy
The simplest Axios proxy setup passes a proxy object with host and port into your request:
javascript
const axios = require(‘axios’);
const response = await axios.get(‘http://example.com’, {
proxy: {
host: ‘your.proxy.host’,
port: 8080
}
});
For testing, hit https://httpbin.org/ip to see which IP your request uses. If you see the proxy’s IP instead of yours, it’s working.

Verify Your Proxy Connection
Test your setup by sending a request to an IP-checking service:
javascript
axios({
method: ‘get’,
url: ‘https://httpbin.org/ip’,
proxy: {
host: ‘123.45.67.89’,
port: 8080
},
timeout: 10000
})
.then(response => console.log(‘Proxy IP:’, response.data))
.catch(error => console.error(‘Error:’, error.message));
If the output shows an IP different from your local one, your Axios proxy is configured correctly. If you want to compare application-level routing with browser-based routing, reviewing Chrome proxy settings can help you understand how traffic is handled in different environments.
Axios Proxy Authentication Explained
Many commercial proxy providers require authentication before allowing requests to pass through their network. Without valid credentials, the proxy server typically returns a 407 authentication error.
Configure Username and Password Authentication
If your proxy requires a username and password, add an auth object to the proxy configuration. This allows Axios to send the necessary credentials with each request so the proxy server can verify your access and process the connection successfully.
javascript
const response = await axios.get(‘https://api.ipify.org’, {
params: { format: ‘json’ },
proxy: {
host: ‘proxy.example.com’,
port: 8080,
auth: {
username: ‘YOUR_USER’,
password: ‘YOUR_PASS’
}
},
timeout: 12000
});
If credentials are correct, you’ll see the proxy’s IP. If wrong, expect a 407 error.

Store Proxy Credentials Securely
Hardcoding secrets is risky. Use environment variables instead:
javascript
const {
PROXY_HOST = ‘proxy.example.com’,
PROXY_PORT = ‘8080’,
PROXY_USER = ‘user1’,
PROXY_PASS = ‘s3cr3t’
} = process.env;
axios.get(‘https://httpbin.org/ip’, {
proxy: {
host: PROXY_HOST,
port: Number(PROXY_PORT),
auth: {
username: PROXY_USER,
password: PROXY_PASS
}
},
timeout: 12000
});
Run with:
bash
PROXY_HOST=your-host PROXY_PORT=8080 PROXY_USER=user1 PROXY_PASS=s3cr3t node app.js
This keeps credentials separate from your codebase.
Using HTTP, HTTPS, and SOCKS Proxies with Axios
Different proxy types offer different levels of compatibility, performance, and anonymity. The following table compares the most common options used with an Axios proxy so you can choose the best fit for your project.
|
Proxy Type |
Best For |
Advantages |
Limitations |
|
HTTP |
Basic web requests |
Easy setup, widely supported |
Less secure |
|
HTTPS |
Secure traffic |
Encrypted connections |
Slightly slower |
|
SOCKS4 |
General proxy routing |
Lightweight |
Not supported via the built-in proxy option; requires socks-proxy-agent |
|
SOCKS5 |
Advanced networking |
Supports multiple protocols |
Not supported via the built-in proxy option; requires socks-proxy-agent |
The right choice depends on your requirements. HTTP and HTTPS proxies work well for most applications, while SOCKS5 proxies offer greater flexibility in advanced networking scenarios.
HTTP Proxies
HTTP proxies are one of the most common options for web scraping, API requests, and general testing. Axios supports HTTP proxies out of the box, allowing you to route requests through a proxy server simply by adding proxy settings to your request configuration.
HTTPS Proxies
HTTPS proxies work similarly to HTTP proxies but add encryption between your application and the proxy server. This extra security makes them a good choice when working with sensitive data, accessing secure APIs, or handling requests that require greater privacy.
HTTPS Proxies via Agent (Recommended)
The built-in proxy option can behave unreliably when the target URL is HTTPS, sometimes ignoring the proxy or failing the TLS tunnel. The robust, production-grade pattern is to set proxy: false and pass a dedicated agent through httpsAgent instead. See the official Axios request config docs for reference.
javascript
// npm install https-proxy-agent
const axios = require(‘axios’);
const { HttpsProxyAgent } = require(‘https-proxy-agent’);
const agent = new HttpsProxyAgent(‘http://user:[email protected]:8080’);
const response = await axios.get(‘https://api.ipify.org?format=json’, {
httpsAgent: agent,
proxy: false, // turn off the built-in proxy so the agent handles routing
timeout: 12000
});
SOCKS4 and SOCKS5 Proxies
SOCKS4 and SOCKS5 proxies offer more flexible network routing than standard HTTP proxies. However, Axios cannot use SOCKS proxies through its built-in proxy configuration. The solution is to set proxy: false and supply a SOCKS agent via both httpAgent and httpsAgent, using the socks-proxy-agent package.
javascript
// npm install socks-proxy-agent
const axios = require(‘axios’);
const { SocksProxyAgent } = require(‘socks-proxy-agent’);
// socks5:// (or socks4://) with optional user:pass@
const agent = new SocksProxyAgent(‘socks5://user:pass@host:1080’);
const response = await axios.get(‘https://httpbin.org/ip’, {
httpAgent: agent,
httpsAgent: agent,
proxy: false, // required so the agent — not Axios — handles routing
timeout: 10000
});
Developers who also manage proxy routing inside browsers may already be familiar with tools such as Foxy Proxy residential proxy, although Node.js applications typically rely on proxy agents instead.
Axios Rotating Proxy Setup
Sending a large number of requests from the same IP address can trigger rate limits, CAPTCHA, or temporary blocks. Routing through multiple proxies helps distribute requests through different IP addresses, making traffic appear more natural. For larger scraping workloads, using an Axios rotating proxy can improve success rates and reduce the risk of detection.
To get started, create a list of available proxies:
export const PROXIES = [
{ host: ‘198.51.100.10’, port: 8080 },
{ host: ‘203.0.113.22’, port: 8080, auth: { username: ‘u1’, password: ‘p1’ } },
{ host: ‘192.0.2.33’, port: 3128 }
];
Next, choose a proxy either randomly or in sequence for each request:
export function pickRandomProxy(list) {
return list[Math.floor(Math.random() * list.length)];
}
let idx = 0;
export function pickRoundRobin(list) {
const p = list[idx % list.length];
idx += 1;
return p;
}
When using a proxy pool, you can assign a different proxy to each request to spread traffic across multiple IPs. If you use a residential rotating proxy service, IP rotation is often handled automatically by the provider, allowing you to benefit from an Axios rotating proxy setup without building additional rotation logic yourself.

Managing Proxy Failures and Retry Logic
Even a reliable Node Axios proxy setup may encounter failures. Implementing retry logic helps maintain application stability. Here’s how to detect failures, retry automatically, switch to backups, and handle timeouts.
Detect Failed Proxies
Not every proxy will work consistently. Proxies can become unavailable, reject connections, or fail authentication. By catching errors and checking response codes, you can quickly identify problematic proxies and prevent them from affecting your application.
try {
const res = await axios.get(url, { proxy, timeout: 10000 });
} catch (err) {
if (err.response?.status === 407) {
console.error(‘407: Proxy auth failed’);
} else if (err.code === ‘ECONNREFUSED’) {
console.error(‘Proxy unreachable’);
}
}
Retry Requests Automatically
Temporary network issues are common when routing through proxies. Instead of failing immediately, you can retry the request with another proxy or attempt the same request again after a short delay.
async function fetchWithRetry(url, proxies, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
const proxy = pickRandomProxy(proxies);
try {
const res = await axios.get(url, { proxy, timeout: 10000 });
return res.data;
} catch (err) {
console.log(`Retry ${i + 1}: Proxy failed`);
}
}
throw new Error(‘All retries failed’);
}
This approach improves reliability by giving your application multiple chances to complete the request successfully.
Switch to Backup Proxies
If one proxy stops working, switching to another proxy can help keep requests running without interruption. This is especially useful when working with a proxy pool or an Axios rotating proxy setup.
async function fetchWithRotation(url) {
const attempt = async () => {
const proxy = pickRoundRobin(PROXIES);
return axios.get(url, { proxy, timeout: 10000 });
};
try {
return await attempt();
} catch {
return await attempt(); // retry with different proxy
}
}
By rotating to a backup proxy, you can reduce downtime and improve overall request success rates.
Implement Timeout Handling
Some proxies may respond very slowly or stop responding altogether. Setting a timeout ensures that a slow proxy cannot keep your application waiting indefinitely.
axios.get(url, {
proxy: { host, port, auth },
timeout: 10000 // 10 seconds
});
A timeout helps your application move on quickly when a proxy becomes overloaded or unavailable, improving both performance and stability.

Performance Optimization for Axios Proxy Requests
Optimizing your proxy setup can improve response times, reduce failed requests, and make your application more efficient. To achieve better performance, consider these best practices:
- Reuse connections with keep-alive agents to reduce the overhead of creating a new connection for every request.
- Set appropriate request timeouts so your application can quickly recover from slow or unresponsive proxies.
- Limit concurrent requests to avoid overwhelming proxy servers and triggering rate limits.
- Implement retry backoff strategies to automatically retry failed requests while reducing pressure on the target server.
- Monitor proxy health regularly to identify unstable or underperforming proxies before they impact results.
- Remove slow or failing proxies from rotation to maintain a reliable proxy pool and improve success rates.
Together, these practices help maintain stable performance, improve success rates, and ensure your Axios proxy infrastructure can handle increasing request volumes more effectively. Comparing Top Providers can also help you choose a proxy service that matches your performance, reliability, and scalability requirements.
Final Verdict
An Axios proxy is an effective way to route requests, improve privacy, and scale data collection workflows in Node.js. By combining proper proxy configuration, secure authentication, rotating IP strategies, and retry logic, we can build more reliable and resilient applications.
Whether you are building a small scraper or a large-scale data pipeline, pairing Axios with a reliable residential proxy is what keeps requests stable and avoids IP-based blocks as you scale.
FAQ – Frequently Asked Questions
Does Axios Support Proxies by Default?
Yes. Axios includes built-in support for HTTP and HTTPS proxies through the proxy configuration object. This makes basic proxy integration simple in Node.js applications.
Should I Use Free Proxies with Axios?
Free proxies can work for testing, but they often suffer from poor reliability, slow speeds, security risks, and frequent downtime. Paid proxies are generally a better choice for production environments.
What Is the Best Proxy Type for Web Scraping?
Residential and rotating proxies are usually the preferred options for web scraping because they offer higher trust levels and lower detection rates than datacenter proxies.
How Many Proxies Do I Need for Large Projects?
The required number depends on request volume and target website restrictions. Small projects may only need a few proxies, while large-scale scraping operations often require dozens or hundreds of rotating IP addresses.