Run a script before Command Prompt stops

I have a Discord Bot that edits a message every second. So if the bot goes off, the message will display the last edit.

I would like to, before closing the Node JS process (using Ctrl + C, closing the Command Prompt or any type of closing the process), edit the message to say something like: “The bot is off”.


// something using discord.js
bot.on("close", myFunction);

// or in node, like in browser 'window.onbeforeunload'
node.beforecloseprocess = myFunction;

If theres a way with discord.js, that would be cool and resolve my problem, but if there a way of using Node Js it self or something in the Command Prompt would be better for future projects aside discord.js.


I would use the discord.js event ‘close’ and call a function that would change the message to ‘The bot is off’.


process.on('SIGINT', function() {