Skip to content

josiasmontag/node-server-graceful-shutdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node http(s) server graceful shutdown

Build Status

Adds a shutdown(callback) to nodes http(s) servers. shutdown() will stop accepting new connections and waits until all pending requests are finished.

This is very similar to the node builtin close() function with the only difference that shutdown() destroys idle connections (keep alive connections). This is done using socket.setTimeout(), which destroys sockets after some time without data transfer (10 seconds as default).

Usage

var enableGracefulShutdown = require('server-graceful-shutdown');

var server = http.createServer(function(req, res) {
  // do stuff
});

server.listen(80);

// enhance server with a 'shutdown' function
enableGracefulShutdown(server);
// you can set the socket idle timeout using the second parameter 
// e.g. enableGracefulShutdown(server, 5000);

// some time later...
server.shutdown(function() {
	// all requests are finished 
	// we can 
	// process.exit() 
	// now
});

About

Graceful shutdown for node http(s) servers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published