Try 500 MB of US mobile proxy data free for 30 days.Start free trial

Integrations

Node.js

Proxy setup for fetch with undici and for axios, over HTTP and SOCKS5.

The examples use mlabs_a1f9c3 / <PASSWORD>. Replace them with your own credential. Suffixes on the username select the session mode and location, see Rotating vs sticky sessions and Location targeting.

fetch with undici

Node's global fetch (Node 18 and later) accepts undici's dispatcher option.

npm install undici
import { ProxyAgent } from 'undici'

const dispatcher = new ProxyAgent(
  'http://mlabs_a1f9c3:<PASSWORD>@proxy.masklabs.io:8080',
)

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

A ProxyAgent pools connections, so requests through one agent share an exit IP until the connection closes. Create a new agent per request to get a new IP each time.

ProxyAgent supports HTTP proxies only. For SOCKS5 use axios with socks-proxy-agent below.

axios

npm install axios https-proxy-agent socks-proxy-agent

HTTP:

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

const agent = new HttpsProxyAgent(
  'http://mlabs_a1f9c3:<PASSWORD>@proxy.masklabs.io:8080',
)

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

proxy: false turns off axios's own proxy handling so the agent does it.

SOCKS5, sticky, pinned to a location:

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

const agent = new SocksProxyAgent(
  'socks5h://mlabs_a1f9c3_loc_ORD_sticky:<PASSWORD>@proxy.masklabs.io:1080',
)

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

Use socks5h, not socks5, so DNS is resolved through the proxy.