Undici Proxy Configuration

← Back to JavaScript / TypeScript Libraries

Undici is a fast, spec-compliant HTTP client and is used in Node.js core. Use Undici with ProxyMesh for high-performance web scraping and API requests. The javascript-proxy-headers package provides a request() function that supports custom proxy headers and returns proxyHeaders in the result.

Installation

npm install undici javascript-proxy-headers

Or from JSR: npx jsr add @proxymesh/javascript-proxy-headers then npm install undici.

Basic Proxy Configuration

Use request() from javascript-proxy-headers with your ProxyMesh proxy. The result includes statusCode, headers, body, and proxyHeaders:

import { request } from 'javascript-proxy-headers/undici';

const { statusCode, headers, body, proxyHeaders } = await request(
  'https://api.ipify.org?format=json',
  {
    proxy: 'http://username:password@proxyhost:31280'
  }
);

console.log(statusCode);
const data = await body.json();
console.log(data.ip);
console.log(proxyHeaders.get('x-proxymesh-ip'));

Custom Proxy Headers

Add proxyHeaders to the options to send custom headers to the proxy:

import { request } from 'javascript-proxy-headers/undici';

const { proxyHeaders } = await request(
  'https://httpbin.org/ip',
  {
    proxy: 'http://username:password@proxyhost:31280',
    proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
  }
);

console.log(proxyHeaders.get('x-proxymesh-ip'));

ProxyMesh Headers Reference

Send these headers to control proxy behavior:

  • X-ProxyMesh-Country - Route through a specific country (e.g., "US"). Only works with world proxy or open proxy
  • X-ProxyMesh-IP - Request a specific outgoing IP address
  • X-ProxyMesh-Not-IP - Exclude specific IPs from rotation

The proxy returns X-ProxyMesh-IP in the response with the IP address used.

Resources

Related JavaScript / TypeScript Proxy Guides

Explore proxy configuration for other JavaScript / TypeScript HTTP libraries:

Start Free Trial