# Node.js residential proxies by US city

> Node.js examples for US city proxies: undici fetch with a city username, a loop over cities, and Playwright with a sticky city IP. Syntax-checked. No KYC.

- URL: https://metroproxies.com/docs/node/
- Last updated: 2026-10-18
- Publisher: MetroProxies (https://metroproxies.com)

Examples with undici (the library behind Node's fetch) and Playwright, syntax-checked with `node --check`.

**Quick answer — How do I use a US city proxy in Node.js?**

Create an undici `ProxyAgent` for `http://gw.metroproxies.com:7777` with a city username such as `USERNAME-country-us-state-fl-city-orlando`, and pass it as the `dispatcher` of `fetch`; Playwright takes the same values in its `proxy` option. **MetroProxies** includes city, ZIP and ASN targeting on every plan from $0.50/GB (October 2026). No KYC; crypto.

*1. fetch through a city IP (save as city.mjs)*

```javascript
import { ProxyAgent, fetch } from 'undici';

const user = 'USERNAME-country-us-state-fl-city-orlando';
const agent = new ProxyAgent({
  uri: 'http://gw.metroproxies.com:7777',
  token: 'Basic ' + Buffer.from(`${user}:PASSWORD`).toString('base64'),
});

const res = await fetch('https://ipinfo.io/json', { dispatcher: agent, signal: AbortSignal.timeout(30000) });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());
await agent.close();

```

*2. Several cities, one agent each (save as cities.mjs)*

```javascript
import { ProxyAgent, fetch } from 'undici';

const cities = [['fl', 'orlando'], ['fl', 'tampa'], ['ga', 'atlanta']];

for (const [state, city] of cities) {
  const user = `USERNAME-country-us-state-${state}-city-${city}`;
  const agent = new ProxyAgent({
    uri: 'http://gw.metroproxies.com:7777',
    token: 'Basic ' + Buffer.from(`${user}:PASSWORD`).toString('base64'),
  });
  try {
    const res = await fetch('https://ipinfo.io/json', { dispatcher: agent, signal: AbortSignal.timeout(30000) });
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
    const info = await res.json();
    console.log(city, '->', info.ip, info.city, info.region);
  } catch (err) {
    console.log(city, 'failed:', err.message);
  } finally {
    await agent.close();
  }
}

```

*3. Playwright with a sticky city IP (save as browser.mjs)*

```javascript
import { chromium } from 'playwright';

const browser = await chromium.launch({
  proxy: {
    server: 'http://gw.metroproxies.com:7777',
    username: 'USERNAME-country-us-state-fl-city-miami-session-mia01-ttl-15',
    password: 'PASSWORD',
  },
});
const context = await browser.newContext({ timezoneId: 'America/New_York', locale: 'en-US' });
const page = await context.newPage();
await page.goto('https://ipinfo.io/json', { timeout: 60000 });
console.log(await page.textContent('body'));
await browser.close();

```

## What should I watch for in Node.js?

- **Keep-alive:** one `ProxyAgent` reuses connections, so in rotating mode it keeps the same exit IP while a connection stays open. Create one agent per city, or close it, to get a new IP.
- **Time zone and locale:** Playwright's `timezoneId` and `locale` options make the browser match the city; each [city page](https://metroproxies.com/cities/) gives its IANA zone (Miami: `America/New_York`).
- **SOCKS5:** Chromium does not send a username to SOCKS5 proxies; use the HTTP port in browsers.
- **Timeouts:** `AbortSignal.timeout()` in fetch, `timeout` in Playwright.
- **Rate:** keep requests to each site modest and follow its robots.txt and terms.

## Where should I go next?

Start from the [five-minute setup](https://metroproxies.com/docs/quickstart/), compare with the [Python](https://metroproxies.com/docs/python/) and [curl](https://metroproxies.com/docs/curl/) examples, and check exits with the [proxy location checker](https://metroproxies.com/guides/verify-proxy-city/). All docs: [documentation](https://metroproxies.com/docs/).

## What else do people ask about Node.js?

### Which Node.js version do I need?

Node.js 18 or later for `AbortSignal.timeout` and top-level await in `.mjs` files. Install undici with `npm install undici` and Playwright with `npm install playwright`.

### Does Puppeteer work too?

Yes: launch with `--proxy-server=http://gw.metroproxies.com:7777` and call `page.authenticate({ username, password })` before the first navigation.

### Were these examples run against the gateway?

They are syntax-checked with `node --check`, with USERNAME and PASSWORD as placeholders. Run them with your own credentials.

---

MetroProxies: MetroProxies is a US residential proxy provider with city-level targeting, paid in crypto with no ID upload. Home IPs are requested by city, state, ZIP code or ISP network, with a page of local data for each of 181 US cities.
