Superagent Proxy Configuration
← Back to JavaScript / TypeScript Libraries
Superagent is a flexible, chainable HTTP client for Node.js and browsers. Use Superagent with ProxyMesh for web scraping and API requests. The javascript-proxy-headers package provides a Superagent-compatible plugin that supports custom proxy headers during HTTPS CONNECT.
Installation
npm install superagent javascript-proxy-headers
Or from JSR: npx jsr add @proxymesh/javascript-proxy-headers then npm install superagent.
Basic Proxy Configuration
Use the proxy plugin from javascript-proxy-headers with Superagent. Configure the proxy URL and optional proxyHeaders; requests go through ProxyMesh and can use a different IP each time.
import superagent from 'superagent';
import { proxyPlugin } from 'javascript-proxy-headers/superagent';
const agent = superagent.agent().use(proxyPlugin({
proxy: 'http://username:password@proxyhost:31280'
}));
const response = await agent.get('https://api.ipify.org?format=json');
console.log(response.body);
console.log(response.headers['x-proxymesh-ip']);
Custom Proxy Headers
Pass proxyHeaders in the plugin options to send custom headers to the proxy:
import superagent from 'superagent';
import { proxyPlugin } from 'javascript-proxy-headers/superagent';
const agent = superagent.agent().use(proxyPlugin({
proxy: 'http://username:password@proxyhost:31280',
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
}));
const response = await agent.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
- Superagent Documentation
- javascript-proxy-headers (Superagent)
- 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: