Node.js Process-Based HTTP Proxy
This package, `node-http-proxy` by 'wddqing', provides an HTTP(S) proxy server for Node.js, distinguished by its support for both single and multi-process modes, configurable via a command-line interface (`nproxy`) or programmatic API. It was last published as version 0.2.4 over five years ago and requires a very old Node.js environment (>=0.10). The package is considered abandoned, lacks active maintenance, and is not compatible with modern Node.js versions or current web standards. It should not be confused with the widely-used and actively maintained `http-proxy` library from `http-party`, which offers a different API and feature set. Due to its age and lack of updates, using this specific `node-http-proxy` in contemporary projects poses significant compatibility and security risks.
Common errors
-
ReferenceError: require is not defined in ES module scope
cause Attempting to use `require()` syntax in a Node.js environment configured for ES Modules (e.g., `"type": "module"` in package.json).fixThis package is strictly CommonJS. Change your project to CommonJS (remove `"type": "module"` from `package.json`) or use `createRequire` for interoperability (not recommended for an abandoned package). -
Error: listen EADDRINUSE: address already in use :::8123
cause The specified proxy port (default 8123) is already being used by another application on your system.fixStop the application using the port or configure `node-http-proxy` to use a different port (e.g., `new ProxyMaster({port: 9000})`). -
Error: The "url" argument must be of type string. Received undefined
cause An upstream proxy request or configuration is missing a target URL, which might stem from outdated internal dependencies or misconfigurations for HTTP client interactions within the proxy.fixThis error often indicates deep incompatibility with modern Node.js `http` modules or internal issues within this specific, old package. There's no straightforward fix; it reinforces the recommendation to migrate to a maintained proxy library.
Warnings
- breaking This package is extremely old (v0.2.4) and abandoned. It is fundamentally incompatible with modern Node.js versions (e.g., Node.js 12+), which have deprecated or removed features it relies on, such as old OpenSSL versions or specific internal Node.js APIs. Running it will likely result in runtime errors.
- gotcha This specific `node-http-proxy` (by 'wddqing') is distinct from the popular and actively maintained `http-proxy` (by `http-party`). Using this abandoned version will lead to compatibility, security, and maintenance issues. Always verify the GitHub repository and npm publisher for proxy libraries.
- breaking Due to its age and reliance on CommonJS, this package will not work directly in Node.js ES Module environments without a CommonJS wrapper or specific build configurations (e.g., using `createRequire`).
- gotcha The package's lack of maintenance implies potential unfixed security vulnerabilities. Using it in production could expose your application to risks such as proxy-related attacks, denial of service, or data breaches.
Install
-
npm install node-http-proxy -
yarn add node-http-proxy -
pnpm add node-http-proxy
Imports
- ProxyMaster
import { ProxyMaster } from 'node-http-proxy';const { proxyMaster: ProxyMaster } = require('node-http-proxy'); - nproxy CLI
node node_modules/node-http-proxy/bin/nproxy.js start
npm install -g node-http-proxy && nproxy start -p 9999 -i 1
Quickstart
const { proxyMaster: ProxyMaster } = require('node-http-proxy');
const port = process.env.PROXY_PORT ? parseInt(process.env.PROXY_PORT) : 8123;
const instances = process.env.PROXY_INSTANCES ? parseInt(process.env.PROXY_INSTANCES) : 1;
console.log(`Starting Node HTTP Proxy on port ${port} with ${instances} instance(s)...`);
const proxymaster = new ProxyMaster({
instance: instances,
port: port
});
proxymaster.start();
// Example of how to stop the server (optional, for demonstration)
// setTimeout(() => {
// console.log('Stopping proxy master...');
// // Note: The original package's stop mechanism is primarily CLI-driven.
// // Programmatic stopping might require deeper inspection or process killing.
// }, 10000);
console.log('Proxy server initialized. Use `curl -x 127.0.0.1:' + port + ' http://www.google.com/` to test.');