In Express.js, is there someway of setting a callback function to be executed when the application shuts down?
You could use the node.js core process 'exit' event like so:
process.on('exit', function() {
// Add shutdown logic here.
});
Of course, the main event loop will stop running after the exit function returns so you can't schedule any timers or callbacks from within that function (e.g. any I/O must be synchronous).