Node.js HTTP Proxy (Node 16+ fork)

1.0.6 · active · verified Wed Apr 22

This package, `http-proxy-node16`, currently at version 1.0.6, is a specialized fork of the popular `node-http-proxy` library. Its primary purpose is to ensure robust compatibility and functionality within Node.js environments version 16.x and later, explicitly addressing potential breaking changes, deprecations, or compatibility issues that might arise when using the original `http-proxy` on newer Node.js runtimes. It offers comprehensive programmable HTTP and WebSocket proxying capabilities, making it an ideal choice for implementing components such as reverse proxies, sophisticated load balancers, or custom HTTP proxy middleware. A key differentiator from the upstream `node-http-proxy` is its explicit focus and testing against Node.js v16 and beyond, providing a reliable solution for applications deployed in these modern environments. The project indicates a maintenance approach welcoming "bug-fix PRs," suggesting a reactive, community-driven cadence for updates. This fork serves as a targeted solution for developers seeking a stable proxying library specifically for their Node.js 16+ applications, where the original project might have broader compatibility concerns or different priorities.

Common errors

Warnings

Install

Imports

Quickstart

Sets up a basic stand-alone proxy server on port 8000 that forwards all HTTP requests to a target server running on port 9000, demonstrating core proxying functionality and basic error handling.

const http = require('http');
const httpProxy = require('http-proxy');

// Create your proxy server and set the target in the options.
// It will listen on port 8000 and proxy requests to the target server on 9000.
const proxy = httpProxy.createProxyServer({ target: 'http://localhost:9000' });
proxy.listen(8000);

// Handle errors from the proxy server, essential for robust applications.
proxy.on('error', function (err, req, res) {
  console.error('Proxy error:', err);
  res.writeHead(500, { 'Content-Type': 'text/plain' });
  res.end('Something went wrong with the proxy.');
});

// Create your target server.
http.createServer(function (req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.write('Request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
  res.end();
}).listen(9000);

console.log('Proxy server listening on http://localhost:8000');
console.log('Target server listening on http://localhost:9000');
console.log('Try visiting http://localhost:8000 in your browser to see the proxy in action.');

view raw JSON →