Axios Proxy Configuration
← Back to JavaScript / TypeScript Libraries
Axios is the most popular JavaScript HTTP client, with a promise-based API and support for Node.js and browsers. Use Axios with ProxyMesh for web scraping, API clients, and anonymous requests.
The javascript-proxy-headers package provides createProxyAxios(), which wraps Axios and supports sending custom proxy headers (e.g. X-ProxyMesh-Country) during HTTPS CONNECT and reading X-ProxyMesh-IP from responses.
Installation
npm install axios javascript-proxy-headers
Or from JSR: npx jsr add @proxymesh/javascript-proxy-headers then npm install axios.
Basic Proxy Configuration
Use createProxyAxios() with your ProxyMesh proxy URL. All requests go through the proxy and can use a different IP each time:
import { createProxyAxios } from 'javascript-proxy-headers/axios';
const client = createProxyAxios({
proxy: 'http://username:password@proxyhost:31280'
});
const response = await client.get('https://api.ipify.org?format=json');
console.log(response.data); // { "ip": "..." }
console.log(response.headers['x-proxymesh-ip']); // IP used by proxy
With IP authentication (whitelist your server IP in the dashboard), omit credentials:
const client = createProxyAxios({
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 { createProxyAxios } from 'javascript-proxy-headers/axios';
const client = createProxyAxios({
proxy: 'http://username:password@proxyhost:31280',
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
});
const response = await client.get('https://httpbin.org/ip');
console.log(response.headers['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 proxyX-ProxyMesh-IP- Request a specific outgoing IP addressX-ProxyMesh-Not-IP- Exclude specific IPs from rotation
The proxy returns X-ProxyMesh-IP in the response with the IP address used.
Resources
- Axios Documentation
- javascript-proxy-headers (Axios)
- javascript-proxy-headers on npm
- @proxymesh/javascript-proxy-headers on JSR
- Example Code on GitHub
Related JavaScript / TypeScript Proxy Guides
Explore proxy configuration for other JavaScript / TypeScript HTTP libraries: