Skip to content
Nefo

Node.js Axios

How to Use Residential Proxies with Node.js and Axios

Attach an https-proxy-agent to Axios, or a socks-proxy-agent for SOCKS5, and send Node.js requests through Nefo residential proxies with rotating or sticky sessions.

Before you start

Nefo offers residential proxies across 227 countries over HTTP, HTTPS, and SOCKS5 with username/password auth. Generate credentials for free in the dashboard proxy generator; only routed traffic consumes your prepaid bandwidth (from 5 GB for $4.50, non-expiring on flexible plans).

Axios needs an explicit agent for reliable HTTPS-over-proxy behavior, so use https-proxy-agent rather than the built-in proxy option.

  • Node.js 18+ with axios installed
  • https-proxy-agent (or socks-proxy-agent for SOCKS5) installed
  • A Nefo account with prepaid bandwidth
  • A username/password from /dashboard/generator
  • Your target country token

Axios proxy agent example

Create an agent and attach it to the request:

For SOCKS5, use socks-proxy-agent with socks5://USERNAME-country-us:[email protected]:11000. Change the country token to target any of 227 countries.

shell
const axios = require('axios');
const { HttpsProxyAgent } = require('https-proxy-agent');

const agent = new HttpsProxyAgent(
  'http://USERNAME-country-us:[email protected]:9000'
);

(async () => {
  const res = await axios.get('https://api.ipify.org', {
    httpAgent: agent,
    httpsAgent: agent,
  });
  console.log(res.data);
})();

Axios rotating vs sticky proxy sessions

Rotating sessions assign a new residential IP per request: HTTP port 9000 or SOCKS5 port 11000. Best for spreading many requests across exits.

Sticky sessions hold one IP from 1 minute up to 24 hours: HTTP port 10000 or SOCKS5 port 12000. Reuse one agent built with a token like USERNAME-country-us-session-api3-lifetime-60 so all requests on that agent share the same IP.

Geo-targeting in the Axios proxy username

Targeting is expressed entirely in the username: country across 227 countries, US state and city, or ASN/ISP within a country. Only the username in the agent URL changes between regions.

Collect data lawfully, honor each site's terms of service, and respect applicable law and sensible request pacing.

Frequently asked questions

Axios's built-in proxy option is unreliable for HTTPS targets. An https-proxy-agent tunnels correctly, so set it as both httpAgent and httpsAgent and leave the built-in proxy option unset.

Start with 5 GB. Keep what you don't use.

Residential bandwidth from $0.53/GB that never expires. Card, PayPal, Apple Pay, Google Pay, Alipay and crypto.