v1.10.82-f67ee7d
Skip to main content
← Back to Hex Proxies

Axios Proxy Integration

Configure Axios to route requests through Hex Proxies.

Axios Proxy Setup

Axios is one of the most popular HTTP clients for Node.js and browser environments. In Node.js, Axios supports proxy configuration through both its built-in `proxy` option and external proxy agents. For HTTPS targets, using a proxy agent is the recommended approach with Hex Proxies.

Installation

npm install axios https-proxy-agent

Recommended: Proxy Agent for HTTPS

import axios from 'axios';

const agent = new HttpsProxyAgent('http://user:pass@gate.hexproxies.com:8080');

const res = await axios.get('https://httpbin.org/ip', { httpsAgent: agent, timeout: 30000, }); console.log(res.data); ```

IP Whitelist Authentication

Whitelist your server IP in the Hex Proxies dashboard and omit credentials:

const agent = new HttpsProxyAgent('http://gate.hexproxies.com:8080');

Using Axios Built-in Proxy Config (HTTP only)

Axios has a built-in `proxy` option, but it only works reliably for HTTP (not HTTPS) targets:

const res = await axios.get('http://httpbin.org/ip', {
  proxy: {
    host: 'gate.hexproxies.com',
    port: 8080,
    auth: { username: 'user', password: 'pass' },
  },
});

For HTTPS targets, always use the `httpsAgent` approach shown above.

SOCKS5 Proxy Support

npm install socks-proxy-agent

const agent = new SocksProxyAgent('socks5://user:pass@gate.hexproxies.com:1080'); const res = await axios.get('https://httpbin.org/ip', { httpsAgent: agent }); ```

Global Proxy Configuration

Apply a proxy to all Axios requests using defaults:

const proxyAgent = new HttpsProxyAgent('http://user:pass@gate.hexproxies.com:8080');
axios.defaults.httpsAgent = proxyAgent;

// All subsequent requests use the proxy const res = await axios.get('https://httpbin.org/ip'); ```

Best Practices

  • **Prefer proxy agents** over the built-in `proxy` option for HTTPS requests — the agent approach handles TLS correctly.
  • **Set timeouts** on every request to avoid hanging calls: `timeout: 30000`.
  • **Reuse the agent** for sticky sessions or create a new agent per request for IP rotation.
  • **Handle errors** with Axios interceptors for centralized retry logic.

Troubleshooting

  • **ECONNREFUSED**: Verify proxy host and port. Check firewall rules for outbound port 8080.
  • **403 responses**: The target site is blocking your request. Switch to residential proxies and add realistic headers.
  • **Proxy auth failures**: Ensure credentials are correct. URL-encode special characters in the password.
  • **HTTPS not working with built-in proxy**: Use `httpsAgent` with `https-proxy-agent` instead of the `proxy` config option.

Integration Steps

1

Create proxy agent

Use https-proxy-agent for HTTPS.

2

Attach to Axios

Pass the agent in request config.

3

Monitor results

Watch for 403s and adjust rotation.

Operational Tips

Keep sessions stable for workflows that depend on consistent identity. For high-volume collection, rotate IPs and reduce concurrency if you see timeouts or 403 responses.

  • Prefer sticky sessions for multi-step flows (auth, checkout, forms).
  • Rotate per request for scale and broad coverage.
  • Use timeouts and retries to handle transient failures.

Frequently Asked Questions

Does Axios support SOCKS5?

Yes, via a SOCKS proxy agent.

Ready to Integrate?

Start using residential proxies with Axios today.