make-fetch-happen Proxy Configuration

← Back to JavaScript / TypeScript Libraries

make-fetch-happen is the fetch implementation used by the npm CLI stack, with support for agents, caching, and retries. Use make-fetch-happen with ProxyMesh when you need npm-style behavior behind a proxy.

The javascript-proxy-headers package provides createProxyMakeFetchHappen(), which passes a ProxyHeadersAgent as agent and wraps responses so you can read response.proxyHeaders.

Installation

npm install make-fetch-happen javascript-proxy-headers

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

Basic Proxy Configuration

Use createProxyMakeFetchHappen() to get a fetch function configured for your proxy:

import { createProxyMakeFetchHappen } from 'javascript-proxy-headers/make-fetch-happen';

const fetch = createProxyMakeFetchHappen({
  proxy: 'http://username:password@proxyhost:31280'
});

const response = await fetch('https://api.ipify.org?format=json');
const data = await response.json();
console.log(data);
console.log(response.proxyHeaders.get('x-proxymesh-ip'));

With IP authentication (whitelist your server IP in the dashboard), omit credentials:

const fetch = createProxyMakeFetchHappen({
  proxy: 'http://proxyhost:port'
});

Custom Proxy Headers

Pass proxyHeaders to send custom headers to the proxy during HTTPS CONNECT (e.g. to select a country with world proxy or open proxy):

import { createProxyMakeFetchHappen } from 'javascript-proxy-headers/make-fetch-happen';

const fetch = createProxyMakeFetchHappen({
  proxy: 'http://username:password@proxyhost:31280',
  proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
});

const response = await fetch('https://httpbin.org/ip');
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