Graceful shutdown of a node.JS HTTP server
You can control the idle timeout for a connection, so you can set how long a keep-alive connection will remain open. For example: server=require(‘http’).createServer(function(req,res) { //Respond if(req.url.match(/^\/end.*/)) { server.close(); res.writeHead(200,{‘Content-Type’:’text/plain’}); res.end(‘Closedown’); } else { res.writeHead(200,{‘Content-Type’:’text/plain’}); res.end(‘Hello World!’); } }).listen(1088); //Set the idle timeout on any new connection server.addListener(“connection”,function(stream) { stream.setTimeout(4000); }); We can test this … Read more