Needle Proxy Configuration
← Back to JavaScript / TypeScript Libraries
Needle is a lightweight HTTP client for Node.js with a simple callback and promise API. Use Needle with ProxyMesh for compact scripts and tools.
The javascript-proxy-headers package provides proxyNeedleGet() (and createProxyNeedle()), which route HTTPS through ProxyHeadersAgent and merge CONNECT response headers onto res.headers where missing.
Installation
npm install needle javascript-proxy-headers
Or from JSR: npx jsr add @proxymesh/javascript-proxy-headers then npm install needle.
Basic Proxy Configuration
Use proxyNeedleGet() with your ProxyMesh proxy URL:
import { proxyNeedleGet } from 'javascript-proxy-headers/needle';
const res = await proxyNeedleGet('https://api.ipify.org?format=json', {
proxy: 'http://username:password@proxyhost:31280'
});
console.log(res.statusCode);
console.log(res.body);
console.log(res.headers['x-proxymesh-ip']);
With IP authentication (whitelist your server IP in the dashboard), omit credentials:
const res = await proxyNeedleGet('https://api.ipify.org?format=json', {
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 { proxyNeedleGet } from 'javascript-proxy-headers/needle';
const res = await proxyNeedleGet('https://httpbin.org/ip', {
proxy: 'http://username:password@proxyhost:31280',
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
});
console.log(res.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
- Needle Documentation
- javascript-proxy-headers (Needle)
- 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: