Node.js HTTP/HTTPS Tunneling Agent

0.0.6 · abandoned · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

This example demonstrates how to create an `httpsOverHttp` tunneling agent and use it with `https.request` to make a secure HTTP request through an HTTP proxy. It highlights the basic configuration for the proxy settings and includes error handling.

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();

view raw JSON →