Registry / http-networking / http-agent

http-agent

JSON →
library0.1.2jsnpmunverified

This package, `http-agent`, is a deprecated and abandoned Node.js library designed to perform sequences of HTTP requests. Last published 15 years ago (July 15, 2011) at version 0.1.2, it targeted very early Node.js environments (>= 0.2.0). It was built upon the now-deprecated `request` library, leveraging it to allow for simple or complex request sequences, including an iterator pattern for dynamic control flow during web crawling. Due to its extreme age and reliance on obsolete dependencies and Node.js versions, it is not suitable for modern applications. There is no active maintenance, nor a release cadence. Modern alternatives like `axios`, `node-fetch`, or Node.js's built-in `fetch` API are highly recommended for current projects, offering better performance, security, and promise-based APIs.

npm install http-agent
INSTALL
IMPORT
SIG · HTTP-AGENT
H
http-agent
http-networkingjavascriptv0.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Agent
const Agent = require('http-agent');
import Agent from 'http-agent';
This package is strictly CommonJS and does not support ES Modules. Attempting to use `import` will result in an error.
create
const agent = Agent.create('host', ['path1', 'path2']);
const agent = require('http-agent').create(...);
The `create` method is a static method on the exported `Agent` class/constructor.

Demonstrates initializing an HTTP agent, defining a sequence of requests, and handling 'next' and 'stop' events.

const Agent = require('http-agent'); // Create an agent for a specific host and a sequence of paths const agent = Agent.create('example.com', ['/', '/about', '/contact']); // Add a listener for the 'next' event, which fires after each request agent.addListener('next', function (err, agent) { if (err) { console.error(`Error visiting ${agent.url}: ${err.message}`); // Decide whether to stop or continue on error // agent.stop(); } else { console.log(`Successfully visited ${agent.url}`); // Access response body: agent.body // Access response headers: agent.headers // Continue to the next URL in the sequence agent.next(); } }); // Add a listener for the 'stop' event, which fires when all URLs are visited or an error occurs agent.addListener('stop', function (err, agent) { if (err) { console.error(`Agent stopped with an unhandled error: ${err.message}`); } else { console.log('Agent finished visiting all specified URLs.'); } }); // Start the agent to begin the sequence of requests agent.start(); // Example of more complex usage (showing a POST request) /* const complexAgent = Agent.create('example.com', [{ method: 'POST', path: '/submit', body: 'data=someValue', headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }]); complexAgent.addListener('next', function(err, agent) { console.log('Complex request done:', agent.url, agent.body); agent.next(); }); complexAgent.start(); */
Debug
Known issues
breakingThis package relies on extremely outdated Node.js versions (>= 0.2.0) and is incompatible with modern Node.js runtimes (e.g., v12+, v14+ due to N-API changes, v16+ due to OpenSSL 3 updates). It will likely fail to run or compile.
fix
Migrate to a modern HTTP client library like `axios`, `node-fetch`, or Node.js's built-in `fetch` API.
affects: >=0.1.2
breakingThe core `request` library, which `http-agent` is built upon, is deprecated and no longer maintained. This means `http-agent` inherits the same end-of-life status and potential for unpatched vulnerabilities.
fix
Replace `http-agent` with a currently maintained and secure HTTP client.
affects: >=0.1.2
gotchaThis package is purely CommonJS (CJS). Attempting to use `import ... from 'http-agent'` in an ES Module (ESM) context will cause a `SyntaxError` or `ERR_REQUIRE_ESM`.
fix
Use `const Agent = require('http-agent');` in CJS files. For ESM projects, migration to a modern ESM-compatible library is necessary.
affects: >=0.1.2
gotchaThe library primarily uses an event-emitter pattern for control flow, which can be less ergonomic and more prone to callback hell compared to modern Promise-based or async/await patterns found in contemporary HTTP clients.
fix
Consider re-implementing request sequencing with `async/await` and modern libraries for cleaner, more readable code.
affects: >=0.1.2
breakingDue to its abandonment, `http-agent` has not received any security updates in over a decade. It likely contains unpatched vulnerabilities that could be exploited in production environments, making it unsafe for any active project.
fix
Discontinue use immediately and migrate to a secure, actively maintained alternative.
affects: >=0.1.2
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module ... not supported
Attempting to use `require()` in an ES Module context or `import` in a CommonJS context when `http-agent` is purely CJS.
fix
Ensure your file is a CommonJS module (e.g., by using `.cjs` extension or setting `"type": "commonjs"` in `package.json` for older Node.js versions) and use `const Agent = require('http-agent');`. Better yet, migrate to an ESM-compatible HTTP client.
Error: Cannot find module 'request'
`http-agent` depends on the `request` library, which may not be installed or might have compatibility issues with your Node.js version.
fix
First, try `npm install request`. If the error persists, it's a strong indicator of incompatibility. Migration to a modern HTTP client is the recommended solution.
TypeError: Agent.create is not a function
The `http-agent` module might not be correctly imported or resolved, or the `Agent` object is not the one expected.
fix
Verify that `require('http-agent')` successfully returns the module. Ensure you are calling `Agent.create()` and not attempting to instantiate `Agent` with `new` or calling `create` as a top-level function.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
requestrequiredCore functionality for making HTTP requests. The 'request' library itself is now deprecated and unmaintained.
Agent activity
8 hits · last 30 days
node
8
Resources