Node.js Client HTTP/HTTPS Request Wrapper
The `client-http` package, at its final release version 0.0.7, provided a simplified API for making HTTP/HTTPS requests in Node.js. Its core features included automatic proxy detection via the `http_proxy` environment variable, manual proxy configuration, basic cookie management, and automatic handling of HTTP 301/302 redirects. It also allowed for custom request headers and timeout settings. Development ceased due to the existence of the more comprehensive 'request' library, and the project is explicitly marked as abandoned by its maintainer. The library's `engines` configuration strictly targets very old Node.js versions (`>=0.6.11 <=0.7.0 || >=0.7.3`), making it fundamentally incompatible with modern Node.js runtimes and entirely unsuitable for current development due to severe security vulnerabilities and lack of maintenance. There is no ongoing release cadence.
Common errors
-
Error: require() of ES Module ... not supported
cause Attempting to import `client-http` using `import` syntax in a Node.js ES Module project.fixThis library is CommonJS-only. If you must use it (which is strongly discouraged), ensure your file is treated as CommonJS (e.g., `.js` file without `"type": "module"` in `package.json`) and use `const http = require('client-http');`. -
Error: ERR_OSSL_EVP_UNSUPPORTED
cause Running `client-http` on modern Node.js versions (e.g., Node.js 17+) where legacy OpenSSL ciphers and hash functions used by the old library or its dependencies are disabled by default.fixThis error signifies fundamental incompatibility with modern Node.js security standards. The only 'fix' is to *not use* this abandoned library. As a temporary workaround for *testing purposes only* (never in production), you can set `NODE_OPTIONS='--openssl-legacy-provider'` environment variable, but this significantly reduces security and does not resolve other issues. -
Error: The 'engines' field is defined with an unsupported Node.js version.
cause Node Package Manager (npm) or Yarn attempting to install `client-http` when the current Node.js version falls outside the very narrow range specified in the `package.json` engines field (`>=0.6.11 <=0.7.0 || >=0.7.3`).fixThis is an installation-time warning/error indicating the package is not designed for your Node.js version. It's a strong signal to *not* use this library. There is no practical fix for using it with modern Node.js.
Warnings
- breaking The package is explicitly abandoned and has not received updates since its final release (0.0.7). It is highly insecure due to unpatched vulnerabilities in its dependencies and its own codebase.
- breaking This library is designed for extremely old Node.js versions (>=0.6.11 <=0.7.0 || >=0.7.3). It will not run correctly on modern Node.js versions (v10+, v12+, etc.) due to API changes, C++ addon incompatibilities, and updated security protocols.
- gotcha The API is entirely callback-based, which is an outdated pattern for asynchronous operations. It does not support Promises or `async/await`, making integration into modern JavaScript codebases cumbersome.
- gotcha Automatic proxy detection relies on the `http_proxy` environment variable. Manual proxy setting is global via `http.setProxy()`, not configurable per-request, which can be limiting for applications requiring fine-grained proxy control.
Install
-
npm install client-http -
yarn add client-http -
pnpm add client-http
Imports
- client-http
import http from 'client-http';
const http = require('client-http'); - http.get
import { get } from 'client-http';const http = require('client-http'); http.get('http://example.com', (data, err, cookie, headers) => { /* ... */ }); - http.request
import { request } from 'client-http';const http = require('client-http'); http.request('http://example.com', (data) => { /* ... */ }, 'body', { 'Content-Type': 'text/plain' }); - http.setProxy
import { setProxy } from 'client-http';const http = require('client-http'); http.setProxy('http://127.0.0.1:8080');
Quickstart
const http = require('client-http');
// Make a simple HTTP GET request to Google
http.get("http://www.google.com/", function(data, err, cookie, headers){
if (err) {
console.error("Error:", err);
return;
}
console.log("Response Data (truncated):");
console.log(data ? data.substring(0, 200) + '...' : '[No Data]');
console.log("Headers:", headers);
});
// Example of setting a timeout
http.setTimeout(5000); // Set timeout to 5 seconds
http.get("https://www.example.com/", function(data, err){
if (err) {
console.error("Timeout Error or other issue:", err);
return;
}
console.log("Example.com response received within 5s.");
});