I have a Node.js app that uses Express. In that app, I have a block that looks like this:
const app = require('./app');
const port = process.env.PORT || 8080;
const server = app.listen(port);
server.on('listening', () =>
console.log(`Application launched on ${app.get('host')}:${port}`)
);
This successfully works. It successfully prints the message when the listening
event is fired. My question is, is there any event I can listen for, for when my server is stopped / shutting down? Or when the server stops listening?
I would like to do some cleanup in this scenario.