# keep-alive-agent

> a keep-alive agent for http and https

Latest version **0.0.1** (published 2012-12-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install keep-alive-agent
pnpm add keep-alive-agent
yarn add keep-alive-agent
bun add keep-alive-agent
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2012-12-05 |
| First published | 2012-12-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Maintainers | ceejbot |
| Keywords | keep-alive, http, https, agent |

## Links

- npm: https://www.npmjs.com/package/keep-alive-agent
- Repository: https://github.com/ceejbot/keep-alive-agent
- npm.io page: https://npm.io/package/keep-alive-agent

## Recent versions

- 0.0.1 (latest) — 2012-12-05

## README

# keep-alive-agent

keep-alive-agent is an HTTP connection pool agent for node.js that re-uses sockets. It is simpler than some agents that also solve this problem because it does not attempt to replace the Agent provided by node. If you want to re-use connections, use this agent. If you want the default node behavior, use the default global agent.

## Usage

__new KeepAliveAgent(*options-hash*)__

Create an instance of the agent, passing the options hash through to the node Agent constructor. These options are in turn passed along to `createConnection()`. The KeepAliveAgent constructor does not use the options itself. The option you are most likely to change is `maxSockets`, which defaults to 5.

To use the agent instance, set it in the `agent` field of the options passed to `http.request()` or `http.get()`. See the [http.request() documentation](http://nodejs.org/api/http.html#http_http_request_options_callback) for details.

__new KeepAliveAgent.Secure(*options-hash*)__

A keep-alive agent that creates tls sockets. Use it the same way you use the http agent.

## Examples

```javascript
var http = require('http'),
    KeepAliveAgent = require('keep-alive-agent');

var getOptions = {
    hostname: 'twitter.com',
    port: 80,
    path: '/dshaw',
    agent: new KeepAliveAgent(),
};
http.get(getOptions, function(response)
{
	response.pipe(process.stdout);
});
```

To re-use secure connections, use the Secure keep-alive agent:

```javascript
var https = require('https'),
    KeepAliveAgent = require('keep-alive-agent');

var getOptions = {
    hostname: 'www.duckduckgo.com',
    port: 443,
    path: '/?q=unicorns',
    agent: new KeepAliveAgent.Secure(),
};
https.get(getOptions, function(response)
{
	response.pipe(process.stdout);
});
```

## See Also

For other implementations, see [agentkeepalive](https://github.com/TBEDP/agentkeepalive) and the [request](https://github.com/mikeal/request) module's [ForeverAgent](https://github.com/mikeal/request/blob/master/forever.js).

## Licence

MIT.

---
_Source: https://npm.io/package/keep-alive-agent · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
