Node.js HTTP/HTTPS Tunneling Agent
The `tunnel` package, currently at version 0.0.6, provides `http.Agent` and `https.Agent` implementations specifically designed for tunneling HTTP and HTTPS traffic through various types of proxies (HTTP over HTTP, HTTPS over HTTP, HTTP over HTTPS, HTTPS over HTTPS). It targets extremely old Node.js environments, supporting versions `0.6.11` through `0.7.0`, and `0.7.3` (as indicated by its `engines` field). This package is considered abandoned, with no new releases or maintenance since 2014, and is not compatible with modern Node.js runtimes. Its primary differentiator was its early support for detailed proxy configurations for different tunneling scenarios within the Node.js `http` module ecosystem, but it has been superseded by actively maintained alternatives.
Common errors
-
TypeError: tunnelingAgent.addRequest is not a function
cause This error occurs because internal APIs of Node.js's `http.Agent` and `https.Agent` classes changed significantly after the versions supported by the `tunnel` package (<=0.7.x). Modern Node.js versions do not expose or expect the `addRequest` method in the same way.fixThis package is incompatible with modern Node.js. Use an alternative like `https-proxy-agent` which is actively maintained and designed for current Node.js versions. -
Error: Cannot find module 'tunnel'
cause This typically indicates the package is not installed, or npm failed to install it correctly due to compatibility issues with your Node.js version, or the package entry on the registry might be broken for older versions.fixFirst, ensure `npm install tunnel` completes successfully. If not, it reinforces that the package is too old or broken. The recommended fix is to abandon this package and use a modern, actively maintained proxy agent library.
Warnings
- breaking The `tunnel` package is abandoned and last updated in 2014. It explicitly targets Node.js versions `<=0.7.x` and is incompatible with all modern Node.js versions (>=1.0.0), leading to runtime errors.
- breaking Due to its abandonment, this package has not received any security updates. It may contain unpatched vulnerabilities related to network communication, proxy handling, or certificate validation, posing significant security risks.
- gotcha The API for `http.Agent` and `https.Agent` has evolved significantly since Node.js 0.7.x. Attempting to use `tunnel` with newer Node.js versions will result in `TypeError`s or unexpected behavior due to incompatible method signatures and internal changes.
Install
-
npm install tunnel -
yarn add tunnel -
pnpm add tunnel
Imports
- tunnel
import tunnel from 'tunnel';
const tunnel = require('tunnel'); - httpsOverHttp
import { httpsOverHttp } from 'tunnel';const { httpsOverHttp } = require('tunnel');
Quickstart
const tunnel = require('tunnel');
const https = require('https');
const tunnelingAgent = tunnel.httpsOverHttp({
proxy: {
host: 'localhost',
port: 3128,
proxyAuth: process.env.PROXY_AUTH ?? '', // Example: 'user:password'
headers: {
'User-Agent': 'Node.js Tunnel Example'
}
}
});
const options = {
host: 'example.com',
port: 443,
agent: tunnelingAgent,
path: '/',
method: 'GET'
};
const req = https.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
res.on('end', () => {
console.log('No more data in response.');
});
});
req.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
});
req.end();