title: How to set the HTTP Keep-Alive timeout in a nodejs server
body: <p>I'm actually doing some load testing against an ExpressJS server, and I noticed that the response send by the server includes a "Connection: Keep-Alive" header. As far as I understand it, the connection will remain opened until the server or the client sends a "Connection: Close" header.</p>
  
  <p>In some implementations, the "Connection: Keep-Alive" header comes up with a "Keep-Alive" header setting the connection timeout and the maximum number of consecutive requests send via this connection.</p>
  
  <p>For example : "Keep-Alive: timeout=15, max=100"</p>
  
  <p>Is there a way (and is it relevant) to set these parameters on an Express server ?</p>
  
  <p>If not, do you know how ExpressJS handles this ?</p>
  
  <p><strong>Edit:</strong>
  After some investigations, I found out that the default timeout is set in the <a href="https://github.com/joyent/node/blob/master/lib/http.js#L1688">node standard http library</a>:</p>
  
  <pre><code>socket.setTimeout(2 * 60 * 1000); // 2 minute timeout
  </code></pre>
  
  <p>In order to change this:</p>
  
  <pre><code>var http = require('http');
  
  http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end("Hello World");
  }).on('connection', function(socket) {
    socket.setTimeout(10000);
  }).listen(3000);
  </code></pre>
  
  <p>Anyway it still looks a little bit weird to me that the server doesn't send any hint to the client concerning its timeout.</p>
  
  <p><strong>Edit2:</strong>
  Thanks to josh3736 for his comment.</p>
  
  <p>setSocketKeepAlive is not related to HTTP keep-alive. It is a TCP-level option that allows you to detect that the other end of the connection has disappeared.</p>