{"id":17688,"library":"http-agent","title":"HTTP Agent (Legacy)","description":"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.","status":"abandoned","version":"0.1.2","language":"javascript","source_language":"en","source_url":"git://github.com/indexzero/http-agent","tags":["javascript","http-agent","iterator","http","webcrawler"],"install":[{"cmd":"npm install http-agent","lang":"bash","label":"npm"},{"cmd":"yarn add http-agent","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-agent","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core functionality for making HTTP requests. The 'request' library itself is now deprecated and unmaintained.","package":"request","optional":false}],"imports":[{"note":"This package is strictly CommonJS and does not support ES Modules. Attempting to use `import` will result in an error.","wrong":"import Agent from 'http-agent';","symbol":"Agent","correct":"const Agent = require('http-agent');"},{"note":"The `create` method is a static method on the exported `Agent` class/constructor.","wrong":"const agent = require('http-agent').create(...);","symbol":"create","correct":"const agent = Agent.create('host', ['path1', 'path2']);"}],"quickstart":{"code":"const Agent = require('http-agent');\n\n// Create an agent for a specific host and a sequence of paths\nconst agent = Agent.create('example.com', ['/', '/about', '/contact']);\n\n// Add a listener for the 'next' event, which fires after each request\nagent.addListener('next', function (err, agent) {\n  if (err) {\n    console.error(`Error visiting ${agent.url}: ${err.message}`);\n    // Decide whether to stop or continue on error\n    // agent.stop(); \n  } else {\n    console.log(`Successfully visited ${agent.url}`);\n    // Access response body: agent.body\n    // Access response headers: agent.headers\n    // Continue to the next URL in the sequence\n    agent.next();\n  }\n});\n\n// Add a listener for the 'stop' event, which fires when all URLs are visited or an error occurs\nagent.addListener('stop', function (err, agent) {\n  if (err) {\n    console.error(`Agent stopped with an unhandled error: ${err.message}`);\n  } else {\n    console.log('Agent finished visiting all specified URLs.');\n  }\n});\n\n// Start the agent to begin the sequence of requests\nagent.start();\n\n// Example of more complex usage (showing a POST request)\n/*\nconst complexAgent = Agent.create('example.com', [{\n  method: 'POST',\n  path: '/submit',\n  body: 'data=someValue',\n  headers: { 'Content-Type': 'application/x-www-form-urlencoded' }\n}]);\ncomplexAgent.addListener('next', function(err, agent) {\n  console.log('Complex request done:', agent.url, agent.body);\n  agent.next();\n});\ncomplexAgent.start();\n*/","lang":"javascript","description":"Demonstrates initializing an HTTP agent, defining a sequence of requests, and handling 'next' and 'stop' events."},"warnings":[{"fix":"Migrate to a modern HTTP client library like `axios`, `node-fetch`, or Node.js's built-in `fetch` API.","message":"This 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.","severity":"breaking","affected_versions":">=0.1.2"},{"fix":"Replace `http-agent` with a currently maintained and secure HTTP client.","message":"The 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.","severity":"breaking","affected_versions":">=0.1.2"},{"fix":"Use `const Agent = require('http-agent');` in CJS files. For ESM projects, migration to a modern ESM-compatible library is necessary.","message":"This 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`.","severity":"gotcha","affected_versions":">=0.1.2"},{"fix":"Consider re-implementing request sequencing with `async/await` and modern libraries for cleaner, more readable code.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.2"},{"fix":"Discontinue use immediately and migrate to a secure, actively maintained alternative.","message":"Due 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.","severity":"breaking","affected_versions":">=0.1.2"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"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.","cause":"Attempting to use `require()` in an ES Module context or `import` in a CommonJS context when `http-agent` is purely CJS.","error":"ERR_REQUIRE_ESM: require() of ES Module ... not supported"},{"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.","cause":"`http-agent` depends on the `request` library, which may not be installed or might have compatibility issues with your Node.js version.","error":"Error: Cannot find module 'request'"},{"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.","cause":"The `http-agent` module might not be correctly imported or resolved, or the `Agent` object is not the one expected.","error":"TypeError: Agent.create is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}