I'm trying to apply this so that my server will tell the clients when it is closed. I don't understand why the server will not emit. It seems like the program closes before it gets a chance to emit, but console.log() works. I think my problem probably has to do with the synchronous nature of process.on as mentioned here, but honestly I don't understand enough about what (a)synchronous really means in this context. Also, I'm on Windows 7 if that helps.
// catch ctrl+c event and exit normally
process.on('SIGINT', function (code) {
io.emit("chat message", "Server CLOSED");
console.log("Server CLOSED");
process.exit(2);
});
I just started messing around with this stuff today so forgive my ignorance. Any help is greatly appreciated!