Node.js HTTP Client Wrapper
This package, `node-http`, provides a minimalistic interface for making HTTP requests within Node.js applications. Originally published over 12 years ago (latest version 0.0.5 from October 2013), it aims to unify the HTTP request process with a chainable API for setting URL, headers, data, and method, alongside event-based callbacks for completion, success, and failure. Due to its age and lack of updates, it is considered abandoned. It exclusively uses CommonJS syntax and does not support modern JavaScript features like Promises or async/await, nor does it officially support contemporary Node.js versions or ESM. Its release cadence was effectively one-off, with no subsequent development. Key differentiators at the time might have been its simplified event-driven approach, but it is now severely outdated compared to actively maintained alternatives like `axios` or Node.js's native `fetch` API.
Common errors
-
TypeError: NodeHttp is not a constructor
cause Attempting to call `NodeHttp` without `new` or treating it as a non-constructor function.fixEnsure you are using `new NodeHttp()` to create an instance. -
ReferenceError: Http is not defined
cause The README uses `new Http()` but the module exports `NodeHttp`. Developers often copy the README literally.fixChange `new Http()` to `new NodeHttp()` after `const NodeHttp = require('node-http');`. -
ERR_REQUIRE_ESM
cause Attempting to `require()` this CommonJS package from an ES Module context in Node.js.fixRefactor your project to use modern ESM-compatible HTTP clients, or if absolutely necessary, use `createRequire` to explicitly load the CommonJS module from an ESM file.
Warnings
- breaking This package (v0.0.5) was last published over 12 years ago. It is completely unmaintained and relies on deprecated patterns and old Node.js APIs, making it highly incompatible with modern Node.js versions (v14+).
- breaking The package uses CommonJS `require()` syntax exclusively and does not provide ES Module exports. This will cause issues in modern Node.js projects configured for ESM or in TypeScript projects targeting ESM.
- gotcha Due to its age, this package likely lacks essential security patches for HTTP vulnerabilities (e.g., related to headers, redirects, certificate validation, or data parsing). Using it in production is a significant security risk.
- gotcha The callback-based API does not support Promises or `async/await`, leading to callback hell and making integration with modern asynchronous JavaScript patterns difficult.
- gotcha The `NodeHttp` constructor is exposed directly. While the README shows `var nodeHttp = new Http;`, the actual imported name is `NodeHttp`. Using `new Http` after `require('node-http')` would result in a `ReferenceError` unless `Http` was separately defined.
Install
-
npm install node-http -
yarn add node-http -
pnpm add node-http
Imports
- NodeHttp
import { NodeHttp } from 'node-http';const NodeHttp = require('node-http'); - Http instance
import NodeHttp from 'node-http'; const nodeHttp = new NodeHttp();
const NodeHttp = require('node-http'); const nodeHttp = new NodeHttp();
Quickstart
const NodeHttp = require('node-http');
const nodeHttp = new NodeHttp();
// Example: Perform a GET request
nodeHttp.GET('http://example.com/data', function (response) {
console.log('Success:', response.responseText);
console.log('Status Code:', response.statusCode);
}).fail(function (error) {
console.error('Failed to fetch data:', error);
});
// Example: Perform a POST request with data
nodeHttp.POST('http://example.com/submit', { key: 'value', id: 123 }, function (response) {
console.log('Post Success:', response.responseText);
}).on('error', function(err) {
console.error('Post Error:', err);
});
// Example: Listening for specific status codes
nodeHttp.on(200, function(response) {
console.log('HTTP 200 OK received for a request.');
});
nodeHttp.on('Not Found', function(response) {
console.error('HTTP 404 Not Found received.');
});