Integrations
Use the proxy from Node.js
fetch with undici's ProxyAgent, and axios with an HTTP or SOCKS5 proxy agent, for rotating and sticky sessions.
Every example below uses the same credential (mlabs_a1f9c3 / <PASSWORD>)
against the standard gateway (proxy.masklabs.io:8080 HTTP,
:1080 SOCKS5). Swap in your own username and password from the dashboard.
fetch, via undici's ProxyAgent
Node's global fetch (Node 18+) is undici under the hood and accepts the
same dispatcher option undici's own fetch does, so ProxyAgent is the
only import you need:
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())
Sticky is the same call with _sticky appended to the username:
const dispatcher = new ProxyAgent(
'http://mlabs_a1f9c3_sticky:<PASSWORD>@proxy.masklabs.io:8080',
)
undici's ProxyAgent tunnels HTTP(S) proxies only, it doesn't speak
SOCKS5. For SOCKS5 from Node, use axios with socks-proxy-agent below.
axios
npm install axios https-proxy-agent socks-proxy-agent
HTTP, rotating:
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,
// Disable axios's own proxy handling — the agent is doing it.
proxy: false,
})
SOCKS5 (socks5h), 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,
})
socks-proxy-agent honors the socks5h scheme by resolving DNS through the
proxy rather than locally, keep the h for the same reason curl and
requests need it.
Picking a mode per job
Rotating is the right default for bulk fetches; reach for _sticky only when
the target needs continuity across requests. See
Rotating vs sticky sessions and location targeting
for the full suffix grammar and current location codes.