I am writing some regression test scripts for an express 4 app, and as the tests close down the server it complains that mongodb has not been closed down correctly, so is there a way to have some callback to notify you when the app is closing and close your stuff down there?
You could try listening on the 'close' event of the server and doing your additional cleanup there.
If you are currently using app.listen() you would have to change to something like:
var server = require('http').createServer(app);
server.on('close', function() {
// ...
});
server.listen(8000);