Registry / http-networking / keep-alive-agent

keep-alive-agent

JSON →
library0.0.1jsnpmunverified

This package provides a basic HTTP and HTTPS connection pooling agent for Node.js, designed to reuse sockets for improved performance by reducing the overhead of establishing new TCP connections. Originally published as version 0.0.1 in December 2012, the package appears to be abandoned, with no significant updates or active development since its initial release. Its primary differentiator was its simplicity, aiming to complement Node.js's default `Agent` rather than replace it. However, the Node.js ecosystem has evolved significantly since then, with native `http.Agent` offering `keepAlive` functionality and more feature-rich, actively maintained alternatives like `agentkeepalive` now widely available. Due to its age and lack of maintenance, it is not recommended for use in modern applications.

npm install keep-alive-agent
INSTALL
IMPORT
SIG · KEEP-ALIVE-AGENT
K
keep-alive-agent
http-networkingjavascriptv0.0.1
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.

KeepAliveAgent
const KeepAliveAgent = require('keep-alive-agent');
import { KeepAliveAgent } from 'keep-alive-agent';
This package is CommonJS-only. Attempting to import it using ESM syntax will likely fail or cause runtime issues.
KeepAliveAgent.Secure
const KeepAliveAgent = require('keep-alive-agent'); const agent = new KeepAliveAgent.Secure();
import { Secure } from 'keep-alive-agent';
The secure agent is a property of the main export, not a separate named export. This package is CommonJS-only.

Demonstrates how to initialize and use the `KeepAliveAgent` for both HTTP and HTTPS requests, reusing sockets for multiple connections.

const http = require('http'); const https = require('https'); const KeepAliveAgent = require('keep-alive-agent'); // Ensure these environment variables are set for testing const HTTP_HOSTNAME = process.env.TEST_HOSTNAME_HTTP || 'example.com'; const HTTPS_HOSTNAME = process.env.TEST_HOSTNAME_HTTPS || 'google.com'; const httpAgent = new KeepAliveAgent({ maxSockets: 10 }); const httpsAgent = new KeepAliveAgent.Secure({ maxSockets: 10 }); // Example using HTTP keep-alive agent const httpOptions = { hostname: HTTP_HOSTNAME, port: 80, path: '/', agent: httpAgent, }; http.get(httpOptions, (response) => { console.log(`HTTP Status: ${response.statusCode}`); response.pipe(process.stdout); }).on('error', (e) => { console.error(`HTTP request error: ${e.message}`); }); // Example using HTTPS keep-alive agent const httpsOptions = { hostname: HTTPS_HOSTNAME, port: 443, path: '/', agent: httpsAgent, }; https.get(httpsOptions, (response) => { console.log(`HTTPS Status: ${response.statusCode}`); response.pipe(process.stdout); }).on('error', (e) => { console.error(`HTTPS request error: ${e.message}`); });
Debug
Known issues
breakingThis package (v0.0.1 from 2012) is severely outdated and is not compatible with modern Node.js features or best practices. It likely contains unpatched security vulnerabilities and may not function as expected or at all with current Node.js versions (e.g., Node.js 16+).
fix
Migrate to Node.js's built-in `http.Agent` with `keepAlive: true` or use actively maintained alternatives like `agentkeepalive` for enhanced features and stability.
affects: <=0.0.1
gotchaNode.js versions prior to 8.0.0 had a potential Denial of Service (DoS) vulnerability (CVE-2019-5739) related to HTTP/S keep-alive connections remaining open for extended periods. This package predates these fixes and would not benefit from the default 5-second `server.keepAliveTimeout` introduced in Node.js 8.0.0.
fix
Do not use this package. Ensure your Node.js runtime is updated to a supported version (Node.js 16 or newer recommended) and use its native `http.Agent` with `keepAlive: true` or a modern alternative like `agentkeepalive`.
affects: <=0.0.1
gotchaUsing an unmaintained package for network operations can lead to `ECONNRESET` errors due to mismatched client/server connection timeouts. Modern `keep-alive` agents or Node.js's built-in options have better mechanisms to handle these scenarios.
fix
Switch to `agentkeepalive` or configure Node.js's native `http.Agent` with appropriate `keepAlive` and `timeout` settings to align client and server expectations.
affects: <=0.0.1
gotchaThere is no community support, bug fixes, or security patches for this abandoned package. Relying on it introduces significant operational risks and technical debt.
fix
Replace this package with a well-supported and actively maintained alternative to ensure stability, performance, and security.
affects: <=0.0.1
Errors
Common errors & fixes
TypeError: KeepAliveAgent is not a constructor
Attempting to use `new KeepAliveAgent()` in an environment where `require('keep-alive-agent')` returned an undefined or invalid value, often due to Node.js version incompatibility or improper module resolution.
fix
This package is unlikely to work correctly with modern Node.js. Use `new http.Agent({ keepAlive: true })` or `new (require('agentkeepalive').HttpAgent)()` instead.
ERR_REQUIRE_ESM
Trying to `require()` this CommonJS package within an ES Module (ESM) context in Node.js, or attempting to `import` it with ESM syntax.
fix
This package is CommonJS-only and fundamentally too old for modern Node.js. Migrate to a modern keep-alive solution that supports ESM, such as `agentkeepalive` or Node.js's built-in `Agent` features.
ECONNRESET
The remote server closed the connection prematurely, or the client attempted to write to a socket that was already closed, often due to misconfigured or outdated keep-alive timeout settings.
fix
This error is common with older `keep-alive` implementations. Upgrade to `agentkeepalive` (which includes better timeout handling) or ensure your client-side `keepAlive` and `timeout` settings are less than the server's `keepAliveTimeout`.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
keep-alive-agent — npm install keep-alive-agent · libregistry