Documentation Python quickstart Blog Free tools Enterprise solutions hello@quanticdata.ioLog in

Axios proxy setup in Node.js: the proxy option, an HTTPS agent, SOCKS5 and sticky sessions

Routing axios through a proxy in Node.js: a sticky line from the QuanticData endpoint generator goes into the proxy option of an axios request, protocol http, host, port 8080 and the login, or into an HttpsProxyAgent or a socks5h:// agent on port 1080 with proxy false; the card lists the three things to check when the request fails.
Routing axios through a proxy in Node.js: a sticky line from the QuanticData endpoint generator goes into the proxy option of an axios request, protocol http, host, port 8080 and the login, or into an HttpsProxyAgent or a socks5h:// agent on port 1080 with proxy false; the card lists the three things to check when the request fails.

To use a proxy in axios, add proxy: { protocol: 'http', host, port, auth: { username, password } } to the request config. For https:// URLs you can instead pass an HttpsProxyAgent as httpsAgent with proxy: false, and for SOCKS5 a SocksProxyAgent with socks5h://. Each example below shows the output it really printed on axios 1.20.0.

Axios sends requests from your own connection unless you tell it otherwise. With a proxy, the site you call sees the proxy's IP address and its country, which is what you need for scraping, price checks and testing geo rules from one machine. The option names below are the ones in the axios documentation; the values come from the QuanticData endpoint generator. The examples with output ran on 24 October 2026 with Node.js 22 through Residential Premium and mobile plans in Malaysia; USER and PASS stand for your own credentials and the printed IPs are masked.

What you need before you start

  • Node.js 20 or newer. The current https-proxy-agent (9.1.0) and socks-proxy-agent (10.1.0) require it, and both are ES modules: load them with import in a .mjs file or in a package with "type": "module".
  • axios 1.16.1 or newer if you want the built-in proxy option to tunnel https:// URLs, explained below. The examples use 1.20.0.
  • The packages: npm install axios https-proxy-agent socks-proxy-agent. The agents are only needed for the agent and SOCKS5 examples.
  • A proxy plan and four values: host, port, username and password. In the QuanticData dashboard they are under My proxies, on the plan's page, in the Endpoint generator: Connection details lists them one by one, which is how axios asks for them.

Three ways to send axios through a proxy

MethodUse it forPort on QuanticDataRemember
The proxy optionAn HTTP proxy for http:// and https:// URLs8080Node.js only; https:// goes through a CONNECT tunnel from axios 1.16.1
https-proxy-agent as httpsAgenthttps:// URLs on any axios 1.x8080Set proxy: false next to it
socks-proxy-agent as httpAgent and httpsAgentSOCKS51080Use socks5h:// and proxy: false
HTTPS_PROXY, HTTP_PROXY, NO_PROXYA proxy without changing the code8080proxy: false turns them off for one request

Step by step: Residential Premium with the proxy option

The QuanticData Endpoint generator for a Residential Premium plan: Malaysia selected as the country, Session set to Sticky with a 30-minute TTL, HTTP protocol, output format user:pass@host:port and the preview line, with the username and password blurred
Step 1 in the QuanticData dashboard: the country your requests should come from, a sticky session and the HTTP protocol.
  1. Generate the line. In the QuanticData dashboard open My proxies, then your plan. In the Endpoint generator choose the Country (Malaysia in this example, with a Region or City if you need one), set Session to Sticky with a Session TTL (minutes) longer than your job, and keep Protocol on HTTP.
  2. Open Connection details. It lists Host, Port, Username and Password, each with a copy button.
  3. Write the proxy object. protocol is the protocol of the proxy, not of the URL you call: 'http' for port 8080, also when the URL starts with https://. Then the host, the port as a number, and auth with the username copied whole and the password.
  4. Set a timeout. Without one, a request that never gets an answer waits forever.
  5. Run it. The answer of ipinfo.io shows the exit: city, region, country and time zone.
Connection details in the QuanticData Endpoint generator: host residentialpremium.quantumproxies.io, port 8080, the username with country my and a session ID, and the password, each with a copy button, credentials blurred
The four values axios asks for, one by one.
import axios from 'axios';

const res = await axios.get('https://ipinfo.io/json', {
  proxy: {
    protocol: 'http',
    host: 'residentialpremium.quantumproxies.io',
    port: 8080,
    auth: {
      username: 'USER-country-my-sid-axios01-ttl-60m',
      password: 'PASS',
    },
  },
  timeout: 30000,
});

const { ip, city, region, country, timezone } = res.data;
console.log(res.status, { ip, city, region, country, timezone });

The output, on 24 October 2026:

200 {
  ip: '103.255.•••.•••',
  city: 'Kuala Terengganu',
  region: 'Terengganu',
  country: 'MY',
  timezone: 'Asia/Kuala_Lumpur'
}
VS Code with proxy-option.mjs: axios.get to https://ipinfo.io/json with the proxy option set to protocol http, host residentialpremium.quantumproxies.io, port 8080 and the username USER-country-my-sid-axios01-ttl-60m; the terminal shows the real result, status 200 from Kuala Terengganu, Terengganu, MY, Asia/Kuala_Lumpur, IP masked; five numbered steps beside it
The proxy option and its real output. Redrawn editor, real code and result.

The username carries the targeting: -country-my picks the exit country, -sid-axios01 names the session and -ttl-60m keeps it for 60 minutes. A curl check through the same session a minute earlier left from the same address, which is the point of a sticky session.

What changed in axios 1.16.1. Older versions sent a request for an https:// URL to the proxy as plain HTTP, with the full URL in it, and the proxy made the TLS connection. Since 1.16.1 (13 May 2026) axios opens a CONNECT tunnel instead: TLS runs end to end between your code and the site, and the proxy login travels only on the CONNECT request. We checked it on the wire against a local listener: axios 1.8.4 sent GET https://ipinfo.io/json, axios 1.20.0 sent CONNECT ipinfo.io:443. Both reach the site through QuanticData; on an older axios, update it or use the agent below.

HTTPS URLs through https-proxy-agent

An agent hands the whole connection to a library built for proxies. It behaves the same on every axios 1.x, keeps the proxy in one URL that you can store in a variable, and fails within a second when the login is wrong, where the built-in option can keep waiting.

import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';

const httpsAgent = new HttpsProxyAgent(
  'http://USER-country-my-sid-axios02-ttl-60m:PASS@residentialpremium.quantumproxies.io:8080'
);

const res = await axios.get('https://ipinfo.io/json', {
  httpsAgent,
  proxy: false,
  timeout: 30000,
});
console.log(res.status, res.data.city, res.data.country);
// 200 Kampung Baru Subang MY

Why proxy: false. It tells axios not to apply any proxy of its own, including one from the environment. We tested it: with HTTPS_PROXY set and no proxy: false, axios 1.20.0 sent the request to the proxy in the environment variable and the agent was never used; with proxy: false the agent carried it. Keep the two together.

Special characters in the password. In a proxy URL, @, :, / and # in the password break the address. Encode it first: `http://${user}:${encodeURIComponent(pass)}@residentialpremium.quantumproxies.io:8080`. The proxy option does not need this, because the password has its own field.

SOCKS5 with socks-proxy-agent

import axios from 'axios';
import { SocksProxyAgent } from 'socks-proxy-agent';

const agent = new SocksProxyAgent(
  'socks5h://USER-country-my-sid-axios03-ttl-60m:PASS@residentialpremium.quantumproxies.io:1080'
);

const res = await axios.get('https://ipinfo.io/json', {
  httpAgent: agent,
  httpsAgent: agent,
  proxy: false,
  timeout: 30000,
});
console.log(res.status, res.data.city, res.data.country);
// 200 Ipoh MY
  • socks5h, not socks5. With socks5:// the agent looks up the site's address on your machine and sends the proxy an IP; with socks5h:// the proxy resolves the name, so the lookup happens in the exit country too.
  • Both agents. httpAgent covers http:// URLs and httpsAgent covers https:// URLs; set both and every request goes through SOCKS5.
  • Port 1080. SOCKS5 has its own port on every QuanticData network; port 8080 is HTTP only.
VS Code with agents.mjs: an HttpsProxyAgent on http://USER-country-my-sid-axios02-ttl-60m:PASS@residentialpremium.quantumproxies.io:8080 and a SocksProxyAgent on socks5h:// port 1080, passed as httpsAgent with proxy false; the terminal shows two real results in Malaysia, Kampung Baru Subang and Ipoh; five numbered steps beside it
An HTTP agent and a SOCKS5 agent in one run, both exits in Malaysia. Redrawn editor, real code and output.

Sticky sessions per request

A scraper that logs in, keeps a cart or walks through pages of results should keep one IP for that job, and a second job should get a different one. With QuanticData the session lives in the username, so the simplest pattern is one agent per session ID, created once and reused:

import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';

const GATEWAY = 'residentialpremium.quantumproxies.io:8080';
const agents = new Map();

// One agent per session ID: the same -sid- keeps its IP, a new one gets a new IP.
function agentFor(sid) {
  if (!agents.has(sid)) {
    const user = `USER-country-my-sid-${sid}-ttl-60m`;
    agents.set(sid, new HttpsProxyAgent(`http://${user}:PASS@${GATEWAY}`));
  }
  return agents.get(sid);
}

async function exitOf(sid) {
  const res = await axios.get('https://ipinfo.io/json', {
    httpsAgent: agentFor(sid),
    proxy: false,
    timeout: 30000,
  });
  return `${res.data.ip} ${res.data.city}`;
}

const a = await exitOf('acct01');
const b = await exitOf('acct01');
const c = await exitOf('acct02');
console.log('acct01 first ', a);
console.log('acct01 again ', b, a === b ? 'same IP' : 'new IP');
console.log('acct02       ', c, c === a ? 'same IP' : 'new IP');
acct01 first  113.211.•••.••• Petaling Jaya
acct01 again  113.211.•••.••• Petaling Jaya same IP
acct02        124.13.•••.••• Taman Petaling new IP
VS Code with sticky.mjs: one HttpsProxyAgent per session ID, the username built as USER-country-my-sid-id-ttl-60m; the terminal shows the real result, acct01 twice on the same masked IP in Petaling Jaya and acct02 on a new IP; four numbered steps beside it
Same session ID, same IP; new session ID, new IP. Redrawn editor, real code and output.
  • Lifetime. -ttl- goes up to 1440 minutes, a full day. After it ends, the next request on that ID gets a new IP.
  • With the proxy option. Put a different username in proxy.auth for each job. For https:// URLs axios keeps a separate tunnel for each proxy and login, so two usernames never share a connection; in our test two session IDs in one process left from two different IPs.
  • Many sessions at once. In the generator, Generate 10 sessions makes ten sticky lines with their own session IDs, ten by default and as many as the Quantity field says; Copy all or Download takes them out.

Which proxy type for which job

Proxy typeIn axiosGood for
Residential Premiumresidentialpremium.quantumproxies.io, HTTP 8080 or SOCKS5 1080; country, region, city or ISP and the session in the usernameMost scraping and testing: home IPs in the country you choose, for example Malaysia residential proxies
ISPOne fixed IP per line from Assigned IPs, HTTP 50100 or SOCKS5 50101, the plan's username and passwordJobs that should keep one address while the plan runs: logged-in sessions, allowlists on the other side
Mobilemobile.quantumproxies.io, HTTP 8080 or SOCKS5 1080, -type-mobile in the username; Global, USA, EU or Asia gateway; IP whitelist availableMobile-first sites and APIs that treat carrier IPs differently

ISP proxies in axios

An ISP plan gives fixed IPs. In the dashboard, Proxy endpoints, Assigned IPs lists them; with Output format set to Proxy URL each line is already in the form an agent takes, http://USER:PASS@IP:50100. Copy one line per job: that IP stays the same while the plan is active, so there is no session ID in the username. The code is the same as for Residential Premium; the sample IP below is masked.

The Assigned IPs panel of a QuanticData ISP plan: Protocol HTTP / HTTPS or SOCKS5, Output format Proxy URL, five IPs masked with port 50100 and username USER, and the formatted output as http://USER:PASS@IP:50100 lines ready to copy
ISP plan: one fixed IP per line, already in proxy URL form. Sample IPs masked.
// the line from Assigned IPs, as an agent
const isp = new HttpsProxyAgent('http://USER:PASS@91.•••.•••.74:50100');
const res = await axios.get('https://example.com/', { httpsAgent: isp, proxy: false, timeout: 30000 });

// or as the proxy option
const res2 = await axios.get('https://example.com/', {
  proxy: { protocol: 'http', host: '91.•••.•••.74', port: 50100, auth: { username: 'USER', password: 'PASS' } },
  timeout: 30000,
});

For SOCKS5 switch the panel's Protocol to SOCKS5: the port in the list becomes 50101, and the line goes into a SocksProxyAgent with socks5h://. The IP your requests leave from is the IP in the line.

Mobile proxies in axios

Mobile works like Residential Premium with two changes: the host is mobile.quantumproxies.io and the username carries -type-mobile. Choose the gateway (Global, USA, EU or Asia) and the protocol, HTTP 8080 or SOCKS5 1080, in the mobile plan's generator. One client per plan with axios.create keeps the code tidy:

The Mobile Endpoint generator: Malaysia selected, Global, USA, EU and Asia gateways, Session set to Sticky, HTTP 8080 or SOCKS5 1080, output format and the preview line with -type-mobile, and the IP whitelist section below, credentials blurred
Mobile: gateway, ports, a sticky session and the IP whitelist.
import axios from 'axios';

const mobile = axios.create({
  proxy: {
    protocol: 'http',
    host: 'mobile.quantumproxies.io',
    port: 8080,
    auth: {
      username: 'USER-country-my-type-mobile-sid-m01-ttl-30m',
      password: 'PASS',
    },
  },
  timeout: 30000,
});

const res = await mobile.get('https://ipinfo.io/json');
console.log(res.status, res.data.city, res.data.country);
// 200 Kuala Lumpur MY
VS Code with isp-mobile.mjs: an axios.create client for an ISP IP 91.x.x.74 on port 50100 with USER and PASS (IP masked) and one for mobile.quantumproxies.io port 8080 with USER-country-my-type-mobile-sid-axios04-ttl-30m; the terminal shows the real mobile result, Kuala Lumpur, MY; five numbered steps beside it
One axios client per plan: ISP (defined, IP masked) and mobile (run). Redrawn editor, real code and output.

Mobile plans also offer IP whitelist authentication: add your server's IP in the generator, then use the host:port list the panel gives for it and leave auth out of the proxy object. Nothing secret sits in the code, which is handy on a fixed server.

Environment variables: HTTPS_PROXY, HTTP_PROXY, NO_PROXY

When a request has no proxy setting, axios reads the proxy from the environment, so a script can go through QuanticData without a code change:

HTTPS_PROXY='http://USER-country-my-sid-job01-ttl-60m:PASS@residentialpremium.quantumproxies.io:8080' \
NO_PROXY='localhost,127.0.0.1' node app.mjs
  • HTTPS_PROXY is used for https:// URLs and HTTP_PROXY for http:// URLs; NO_PROXY lists hosts that go direct.
  • proxy: false on a request ignores them, as in the agent examples above.
  • On Node versions with built-in proxy support started with NODE_USE_ENV_PROXY=1 or --use-env-proxy, axios leaves the environment variables to Node; an explicit proxy option is still handled by axios.

Axios proxy not working: errors and fixes

VS Code with errors.mjs and its real output: HTTP sent to port 1080 gives ECONNRESET, protocol https on the HTTP port gives EPROTO, a wrong SOCKS5 password gives Socks5 Authentication failed, and HTTP on port 8080 with the right login returns 200 from MY; four numbered steps beside it
Three mistakes and the fix, with the errors axios really printed. Redrawn editor, real code and output.
What you seeUsual causeFix
The request hangs (https:// URL with the proxy option), Parse Error: Missing expected CR after response line, or Proxy connection ended before receiving CONNECT responseUsername or password wrong, or a country code in the username that does not existCopy the line again from the generator; set timeout on every request and, for https:// URLs, use https-proxy-agent so a bad login fails at once
ECONNRESET or socket hang upHTTP sent to the SOCKS5 port 1080HTTP on 8080, SOCKS5 on 1080
EPROTO ... wrong version numberprotocol: 'https' in the proxy objectprotocol: 'http': it is the proxy's protocol, not the URL's
Socks5 Authentication failedWrong username or password on SOCKS5Copy both again; encode special characters in the password
Socket closed after the timeoutA SOCKS agent pointed at port 8080Port 1080 for SOCKS5
Your own IP in the answerThe code runs in a browser, where the proxy option does nothing, or proxy: false without an agentRun it in Node.js; give the request a proxy or an agent
Wrong countryNo -country- in the usernameGenerate the line with a country

One test outside your code settles most cases in a minute. If this returns an address in the right country, the proxy works and the problem is in the axios config; see how to use a proxy with curl for more.

curl -x http://residentialpremium.quantumproxies.io:8080 \
  -U "USER-country-my-sid-test-ttl-10m:PASS" https://ipinfo.io/json

HTTP or SOCKS5 with axios

Start with HTTP on port 8080 and the proxy option: no extra package, and since axios 1.16.1 https:// URLs are tunnelled end to end. Pick SOCKS5 on port 1080 when the rest of your stack already speaks SOCKS or you want the proxy to resolve hostnames; the details are on the page for SOCKS5 proxies. For pages that need a real browser, the same lines work in Puppeteer; for fetch and undici, see how to use a proxy in Node.js; the Python equivalent is Python Requests. The plans themselves are on the pages for QuanticData residential proxies, ISP proxies and mobile proxies.

Before you scrape

A proxy changes where requests come from, not what you are allowed to collect. Keep to each site's terms and to the law where you work, send requests at a pace the site can handle, and give each job its own session.

Sources & further reading

FAQ

Quick answers on axios proxy.

Something else? Ask us

How do I set a proxy in axios?

Add a proxy object to the request config: proxy: { protocol: 'http', host, port, auth: { username, password } }. With QuanticData the host is residentialpremium.quantumproxies.io, the port 8080, and the username carries the country and the session. Set it on one request, or on an instance with axios.create. The option works in Node.js only.

Does the axios proxy option work with HTTPS URLs?

Yes. Since axios 1.16.1 a request for an https:// URL goes through a CONNECT tunnel, with TLS end to end and the proxy login sent only on the CONNECT. Keep protocol: 'http': it is the protocol of the proxy, not of the URL. On older versions, update axios or pass an HttpsProxyAgent as httpsAgent with proxy: false.

How do I use a SOCKS5 proxy with axios?

Install socks-proxy-agent, create new SocksProxyAgent('socks5h://USER:PASS@host:1080') and pass it as both httpAgent and httpsAgent, with proxy: false. Use socks5h so the proxy resolves hostnames; with socks5 the lookup happens on your machine.

What does proxy: false do in axios?

It turns off every proxy axios would apply itself, including the HTTP_PROXY and HTTPS_PROXY environment variables. Set it whenever you pass a proxy agent: in our test with HTTPS_PROXY set and no proxy: false, axios 1.20.0 sent the request to the environment proxy and ignored the agent.

Does axios use the HTTP_PROXY and HTTPS_PROXY environment variables?

Yes, when a request has no proxy setting: HTTPS_PROXY for https:// URLs, HTTP_PROXY for http:// URLs, and NO_PROXY for hosts that should go direct. A proxy option on the request takes their place, and proxy: false ignores them.

Why is my axios proxy not working?

Check, in order: the port matches the type (HTTP 8080, SOCKS5 1080 on QuanticData), protocol is 'http', the username is copied whole with a country code that exists, and the code runs in Node.js, not in a browser. A request that hangs, "Parse Error: Missing expected CR after response line" or "Proxy connection ended before receiving CONNECT response" means the login or the country code is wrong: copy the line again from the generator.

How do I keep the same IP across axios requests?

Use a sticky session: put the same -sid- in the username, for example USER-country-my-sid-job01-ttl-60m, and reuse it. The IP holds for the lifetime in -ttl-, up to 1440 minutes. A new session ID gives a new IP. One agent per session ID, created once, is the simplest way to manage it.

A sticky IP for every axios job

Residential Premium, ISP and mobile proxies with country targeting and sticky sessions up to 1440 minutes, HTTP and SOCKS5, copied straight from the endpoint generator into your axios config.

Related reading