node-fetch Proxy Configuration

← Back to JavaScript / TypeScript Libraries

node-fetch brings the Fetch API to Node.js. Use node-fetch with ProxyMesh for web scraping and API requests. The javascript-proxy-headers package provides proxyFetch(), which supports custom proxy headers and exposes proxy response headers on response.proxyHeaders.

Installation

npm install node-fetch javascript-proxy-headers

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

Basic Proxy Configuration

Use proxyFetch() with your ProxyMesh proxy URL. The API is similar to fetch() with added proxy and optional proxyHeaders:

import { proxyFetch } from 'javascript-proxy-headers/node-fetch';

const response = await proxyFetch('https://api.ipify.org?format=json', {
  proxy: 'http://username:password@proxyhost:31280'
});

const data = await response.json();
console.log(data.ip);
console.log(response.proxyHeaders.get('x-proxymesh-ip'));  // IP used by proxy

Custom Proxy Headers

Add proxyHeaders to send custom headers to the proxy (e.g. X-ProxyMesh-Country with world proxy or open proxy):

import { proxyFetch } from 'javascript-proxy-headers/node-fetch';

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

console.log(response.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