I want to tell Node.js to always do something just before it exits, for whatever reason — Ctrl+C, an exception, or any other reason.

I tried this:

process.on('exit', function (){
    console.log('Goodbye!');
});

I started the process, killed it, and nothing happened. I started it again, pressed Ctrl+C, and still nothing happened…

12 Answers
12

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *