Reverse HTTP Client
reverse-http is a JavaScript client library designed to establish a reverse HTTP connection to a server that supports the Reverse HTTP (PTTH/1.0) draft specification. This unique protocol allows an outbound HTTP connection from a client to act as a server, receiving incoming HTTP requests from the remote endpoint. The library is currently at version 1.3.0 and explicitly requires a Node.js runtime of version 0.12 or higher. Given the extremely old engine requirement, it is effectively unmaintained for modern Node.js environments and does not follow a current release cadence. Its primary differentiator is its specific implementation of the niche PTTH/1.0 protocol, offering a way for clients behind restrictive firewalls or NATs to expose services.
Common errors
-
ReferenceError: require is not defined
cause Attempting to use the CommonJS `require()` function in an ECMAScript Module (ESM) context in a modern Node.js project.fixFor ESM projects, use `import reverseHttp from 'reverse-http';`. If the file is part of a CommonJS module, ensure `type: 'module'` is not set in `package.json` or the file uses `.cjs` extension. -
TypeError: reverseHttp is not a function
cause Incorrectly importing the CommonJS default export using named ESM import syntax (e.g., `import { reverseHttp } from 'reverse-http';`).fixUse a default ESM import: `import reverseHttp from 'reverse-http';`. CommonJS modules export a single value that becomes the default export when imported via ESM. -
Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE (or similar SSL/TLS errors)
cause The very old Node.js version targeted by this package might use outdated or insecure TLS protocols and cipher suites, leading to handshake failures with modern servers that enforce stricter security policies.fixThis issue is often a symptom of the package's fundamental incompatibility with modern environments. There is no direct fix for this package's core. You would need to move to a maintained library or explicitly, and insecurely, disable certificate verification (`rejectUnauthorized: false`), which is strongly discouraged for production.
Warnings
- breaking The package explicitly targets Node.js version `>= 0.12`. This extremely old engine requirement means it is highly likely to be incompatible with modern Node.js versions (e.g., v16, v18, v20+) due to significant changes in core APIs, dependency updates, and underlying system libraries.
- gotcha The library implements the 'Reverse HTTP' (PTTH/1.0) draft specification, which is a niche and potentially unmaintained protocol. This may lead to interoperability issues with contemporary HTTP servers or load balancers, and a lack of community support.
- gotcha This package does not ship with TypeScript type definitions. When used in a TypeScript project, you will either need to create manual declaration files (`.d.ts`) or use `any` types, which reduces type safety.
- gotcha When using the `tls: true` option, the underlying Node.js 0.12 TLS implementation and its associated OpenSSL libraries are severely out of date. This could expose applications to known cryptographic vulnerabilities, compromising connection security and potentially making it impossible to connect to modern, secure servers.
Install
-
npm install reverse-http -
yarn add reverse-http -
pnpm add reverse-http
Imports
- reverseHttp
const reverseHttp = require('reverse-http') - reverseHttp (ESM default import)
import { reverseHttp } from 'reverse-http'import reverseHttp from 'reverse-http'
- ReverseServer (instance)
import { ReverseServer } from 'reverse-http'const server = reverseHttp(opts)
Quickstart
const reverseHttp = require('reverse-http')
const opts = {
hostname: 'example.com',
path: '/foo'
}
// Open an HTTP connection to example.com and accept reverse HTTP
// requests back to this machine. This effectively turns the client
// into a server for requests coming back through the established tunnel.
reverseHttp(opts, function (req, res) {
console.log('Incoming request:', req.method, req.url)
res.writeHead(201, {
'Content-Type': 'text/plain',
'Content-Length': 11
})
res.end('Hello World')
})