ProxioDocs
Integrations

Node.js

Route native fetch, Axios, Got, and SOCKS5 clients through Proxio in Node.js, with install commands, complete scripts, and a verify step for each.

Node has no shortage of ways to make an HTTP request, and each one takes a proxy a little differently. This guide covers native fetch, Axios, Got, and a standalone SOCKS5 example you can drop into any of them.

Native fetch (undici)

npm install undici

Node 18+ ships a global fetch built on undici, but ProxyAgent itself isn't global, so you still import it. Native fetch reads a dispatcher option. It does not understand the agent option that https-proxy-agent or socks-proxy-agent provide (those target Node's older http(s) module, and Axios and Got below use them for exactly that reason).

import { ProxyAgent } from 'undici'

const HOST = 'geo.proxio.cc'
const PORT = 16666
const USERNAME = 'USERNAME'
const PASSWORD = 'PASSWORD'

const proxyAuth = Buffer.from(`${USERNAME}:${PASSWORD}`).toString('base64')

const dispatcher = new ProxyAgent({
  uri: `http://${HOST}:${PORT}`,
  token: `Basic ${proxyAuth}`,
})

// fetch is global in Node 18+, so only ProxyAgent needs an import.
const response = await fetch('https://ipinfo.io/json', { dispatcher })
console.log(await response.json())

Use the token option

Set credentials with token, not by embedding USERNAME:PASSWORD@ in the uri. ProxyAgent accepts embedded credentials in principle, but the token option is what undici's own docs recommend and is the one that reliably sends Proxy-Authorization on every request.

Verify: run the script. The printed JSON's ip field is the proxy's exit IP, not your machine's. To reuse one dispatcher for every fetch call instead of passing it each time, call setGlobalDispatcher(dispatcher) once at startup.

Axios

npm install axios https-proxy-agent

Axios's built-in proxy option sends a plain forwarded request instead of an HTTP CONNECT tunnel for https:// targets, so requests to HTTPS URLs through it often fail or silently skip the proxy. Set proxy: false and supply an agent from https-proxy-agent instead, which handles the CONNECT tunnel correctly for both schemes.

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

const proxyUrl = 'http://USERNAME:[email protected]:16666'
const agent = new HttpsProxyAgent(proxyUrl)

const { data } = await axios.get('https://ipinfo.io/json', {
  httpAgent: agent,
  httpsAgent: agent,
  proxy: false,
})
console.log(data)

Verify: run the script. data.ip is the proxy's exit IP.

Got

npm install got hpagent

Got's agent option takes separate http and https agents. hpagent is built for this and keeps connections alive between requests; https-proxy-agent (and http-proxy-agent) work as a drop-in alternative with the same shape.

import got from 'got'
import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent'

const proxyUrl = 'http://USERNAME:[email protected]:16666'

const body = await got('https://ipinfo.io/json', {
  agent: {
    http: new HttpProxyAgent({ proxy: proxyUrl }),
    https: new HttpsProxyAgent({ proxy: proxyUrl }),
  },
}).json()

console.log(body)

Verify: run the script. body.ip is the proxy's exit IP.

SOCKS5 (any client)

npm install socks-proxy-agent

socks-proxy-agent reads the scheme directly out of the proxy URL. Use socks5h:// so the hostname resolves on the proxy side instead of locally, the same reasoning as cURL and Python.

import https from 'node:https'
import { SocksProxyAgent } from 'socks-proxy-agent'

const agent = new SocksProxyAgent('socks5h://USERNAME:[email protected]:16666')

https.get('https://ipinfo.io/json', { agent }, (res) => {
  let body = ''
  res.on('data', (chunk) => (body += chunk))
  res.on('end', () => console.log(body))
})

The same agent instance drops straight into Axios's httpAgent/httpsAgent or Got's agent.https, exactly like the HTTP examples above.

Verify: run the script. The printed body is JSON with the proxy's exit IP.

On this page