Free test available for France , UK or SG on Telegram Join Telegram
Node.js Setup Guide

Mobile Proxy Node.js Setup

Step-by-step mobile proxy Node.js setup tutorial. Configure axios, node-fetch, Puppeteer, and Playwright with dedicated 4G/5G carrier IPs for reliable JavaScript automation.

PXM2 Proxies September 22, 2026 8 min read
Node 18+ Runtime support
axios & fetch HTTP clients
Puppeteer & Playwright Headless browsers
7+ Countries available
  • https-proxy-agent integration — route axios and native fetch requests through authenticated HTTP tunnels.
  • socks-proxy-agent support — full SOCKS5 protocol coverage with remote DNS resolution in modern Node.js runtimes.
  • Puppeteer page authentication — handle proxy credential prompts using page.authenticate() or Chrome runtime flags.
  • Playwright context isolation — assign dedicated mobile proxies per browser context for leak-free multi-accounting.
4G / 5G Mobile Proxies JavaScript & TypeScript Ready
Target runtimesNode.js, Bun, Deno
Libraries coveredaxios, Undici, Puppeteer, Playwright
Protocol supportHTTP CONNECT, SOCKS5
AuthenticationBasic Auth & Context Dispatchers
Custom Agent Dispatchers

Headless Browser Isolation

Rotation Resilient

Node.js Proxy Options

Unlike browser runtimes or Python, Node.js does not automatically read HTTP_PROXY environment variables out of the box for built-in HTTP requests. In modern JavaScript and TypeScript backends, routing outbound traffic through a proxy requires configuring an Agent dispatcher or passing network parameters into high-level browser automation frameworks.

Tool / Library Proxy Method Authentication Handling Use Case
axios https-proxy-agent Inline URL credentials REST APIs, backend microservices
fetch (Node 18+) undici ProxyAgent ProxyAgent basic auth Standard web APIs, Next.js backends
Puppeteer args + page.authenticate CDP event intercept Headless Chrome automation
Playwright Context proxy config Native server object Modern browser scraping & tests

axios and node-fetch Setup

When using axios, developers frequently attempt to pass a basic { host, port, auth } proxy object. While this works for plaintext HTTP, it often causes connection reset errors on HTTPS targets. The industry standard solution is to install https-proxy-agent or socks-proxy-agent to establish clean HTTP CONNECT tunnels.

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

// Define dedicated PXM2 mobile proxy endpoint
const proxyUrl = 'http://user123:secret456@proxy.pxm2.io:8000';
const httpsAgent = new HttpsProxyAgent(proxyUrl);

// Create reusable axios client instance
const client = axios.create({
  httpsAgent,
  timeout: 15000,
  headers: {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
  },
});

async function checkCarrierIp() {
  try {
    const response = await client.get('https://ipinfo.io/json');
    console.log('Connected through mobile IP:', response.data.ip);
  } catch (err) {
    console.error('Proxy request failed:', err.message);
  }
}

checkCarrierIp();
The HttpsProxyAgent guarantees end-to-end TLS encryption through the mobile modem

For SOCKS5 proxies in Node.js, install socks-proxy-agent and initialize SocksProxyAgent('socks5h://user:pass@proxy.pxm2.io:1080'). The socks5h protocol ensures remote DNS resolution without client-side leaks.

Puppeteer Proxy Configuration

Puppeteer launches an external Chromium binary. Because Chrome does not accept inline user and password credentials in its command line arguments, Puppeteer requires a two-step process: launching the browser with --proxy-server and calling page.authenticate() to supply credentials over the Chrome DevTools Protocol (CDP).

Puppeteer proxy launch and authentication
import puppeteer from 'puppeteer';

async function runBrowser() {
  const browser = await puppeteer.launch({
    headless: 'new',
    args: [
      // 1. Pass host and port to Chrome flags
      '--proxy-server=http://proxy.pxm2.io:8000',
      '--no-sandbox',
    ],
  });

  const page = await browser.newPage();

  // 2. Intercept 407 authentication challenges
  await page.authenticate({
    username: 'user123',
    password: 'secret456',
  });

  await page.goto('https://ipinfo.io', { waitUntil: 'domcontentloaded' });
  const ip = await page.$eval('body', el => el.innerText);
  console.log('Puppeteer IP verified:', ip);

  await browser.close();
}

runBrowser();
Calling page.authenticate() before navigating prevents modal authentication lockups

Playwright Proxy Setup

Playwright provides cleaner proxy ergonomics than Puppeteer. Instead of relying on CDP authentication interception, Playwright allows you to define proxy settings at the context level. This makes it possible to assign different mobile proxies to separate browser contexts concurrently inside a single Chromium instance.

Isolated context proxies in Playwright
import { chromium } from 'playwright';

async function main() {
  const browser = await chromium.launch({ headless: true });

  // Create isolated context with dedicated mobile proxy
  const context = await browser.newContext({
    proxy: {
      server: 'http://proxy.pxm2.io:8000',
      username: 'user123',
      password: 'secret456',
    },
    userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36',
  });

  const page = await context.newPage();
  await page.goto('https://api.ipify.org?format=json');
  console.log(await page.textContent('body'));

  await context.close();
  await browser.close();
}

main();
Context isolation allows running multiple mobile proxies without spawning multiple browsers

Node.js Proxy Best Practices

When running Node.js scrapers and bots at scale, proper connection pooling and memory hygiene are vital:

  • 1. Enable Keep-Alive on Proxy Agents
    Always set keepAlive: true in your HttpsProxyAgent options. Reusing persistent TCP sockets saves 100ms–250ms of cellular latency on every sequential request.
  • 2. Close Idle Contexts
    In Playwright and Puppeteer, never leave unused browser contexts or pages open. Lingering contexts consume memory and keep open socket connections to the cellular modem.
  • 3. Handle On-Demand Rotation Delays
    When triggering an IP rotation via the PXM2 webhook in Node.js, wrap the rotation call in a Promise that pauses for 6 seconds before resolving your request queue.
🇫🇷

France

3 Operators 20-100 Mbps
Starting from
$4.34 for 1 hour
4G
Available Operators:
Orange Bouygues SFR
🇮🇳

India

2 Operators 20-30 Mbps
Starting from
$2.74 for 1 hour
4G
Available Operators:
Airtel Vodafone Idea (Vi)
🇵🇱

Poland

1 Operator 20-80 Mbps
Starting from
$3.99 for 1 hour
4G
Available Operators:
Play
View all locations →

Frequently Asked Questions

How do I use a mobile proxy with axios in Node.js?

In modern axios, use https-proxy-agent or socks-proxy-agent to create an httpAgent or httpsAgent and pass it to your axios instance. This bypasses issues with basic proxy object configurations and ensures full CONNECT tunnel support for HTTPS.

How does Playwright handle proxy authentication?

Playwright supports proxy authentication directly in browser.newContext({ proxy: { server, username, password } }) or at browser launch. Unlike Puppeteer, Playwright handles authentication at the network protocol layer without requiring page-level popups.

Can I use mobile proxies with the native Node.js fetch API?

Yes. In Node.js 18 and newer, global fetch uses Undici. You can configure a proxy by passing a custom Dispatcher instance from undici (ProxyAgent), or by setting the standard HTTP_PROXY environment variables with undici-fetch.

Why do WebSocket connections fail over Node.js HTTP proxies?

WebSockets require an HTTP 101 Switching Protocols upgrade. When routing WebSockets through an HTTP proxy, ensure your proxy agent supports the HTTP CONNECT method, or switch to a SOCKS5 proxy which tunnels raw TCP streams without inspecting payload headers.

How do I manage mobile proxy IP rotation in Node.js scripts?

When rotating via API, execute an HTTP GET request to your PXM2 rotation URL. Use a short delay of 5 to 10 seconds to allow the cellular modem to establish a new carrier session, then execute an IP check against https://api.ipify.org before continuing.

Explore related developer tutorials, language integrations, and mobile proxy infrastructure guides.

Developer Guides

Platform & Scraping Guides

Accelerate Your Node.js Automation with Carrier Proxies

Dedicated 4G/5G mobile modems with unlimited data, low latency, and instantaneous API-driven IP rotation.

Get a Mobile Proxy