Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Node.js Proxy Examples — axios, fetch & got with Residential Proxies

Copy-paste recipes for routing Node.js HTTP clients through an authenticated residential proxy: axios, native fetch (undici), and got.

axios

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

const USER = process.env.QP_USER;
const PASS = process.env.QP_PASS;

const agent = new HttpsProxyAgent(
  `http://${USER}-country-us:${PASS}@residentialboson.quantumproxies.io:9000`
);

const { data } = await axios.get("https://ipinfo.io/json", {
  httpsAgent: agent,
  proxy: false, // important: let the agent handle it
});
console.log(data);

Gotcha: with axios you must set proxy: false when using an agent, otherwise axios' own proxy handling conflicts with it.

Native fetch (Node 18+, undici)

import { ProxyAgent } from "undici";

const dispatcher = new ProxyAgent(
  `http://${USER}:${PASS}@residentialboson.quantumproxies.io:9000`
);

const res = await fetch("https://ipinfo.io/json", { dispatcher });
console.log(await res.json());

got

import got from "got";
import { HttpsProxyAgent } from "https-proxy-agent";

const body = await got("https://ipinfo.io/json", {
  agent: { https: new HttpsProxyAgent(proxyUrl) },
}).json();

Sticky sessions & geo-targeting

The gateway takes routing flags in the username — no API calls needed:

Flag Effect
-country-us US exit IP
-country-us-state-texas-city-houston city-level exit
-session-k3px-lifetime-30 keep the same IP for 30 min (use port 10000)

Run it:

npm install axios https-proxy-agent undici
QP_USER=... QP_PASS=... node axios-proxy.js

Credentials

Examples use QuantumProxies residential proxies (rotating port 9000, sticky 10000, SOCKS5 12000). Pay-per-GB, 195+ countries — get a username/password pair at app.quantumproxies.io.

About

Residential proxy examples for Node.js: axios, native fetch (undici) and got, with sticky sessions and geo-targeting.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages