It doesn't seem to be documented but you can pass an http agent to superagent with the function agent
.
So you could create a keep-alive agent with this module: https://www.npmjs.org/package/agentkeepalive and pass it to superagent.
Something like this:
util = require('util');
util.debuglog = require('debuglog');
var http = require('http');
var request = require('superagent');
var Agent = require('agentkeepalive');
var keepaliveAgent = new Agent({
maxSockets: 100,
maxFreeSockets: 10,
timeout: 60000,
keepAliveTimeout: 30000 // free socket keepalive for 30 seconds
});
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('req.httpVersion seen on server:' + req.httpVersion);
res.write('\nreq.headers.connection seen on server:' + req.headers.connection);
res.end();
}).listen(1337, '0.0.0.0');
request
.get('localhost:1337/helloword')
.agent(keepaliveAgent)
.end(function (err, res) {
console.log(res.text);
});