keep-alive-agent
a keep-alive agent for http and https
Last updated 12 years ago by ceejbot .
MIT · Repository · Original npm · Tarball · package.json
$ npm install keep-alive-agent 
SYNC missed versions from official npm registry.

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 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

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:

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 and the request module's ForeverAgent.

Licence

MIT.

Current Tags

  • 0.0.1                                ...           latest (12 years ago)

1 Versions

  • 0.0.1                                ...           12 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE