Skip to content

Instantly share code, notes, and snippets.

@GreepTheSheep
Last active November 11, 2022 13:23
Show Gist options
  • Save GreepTheSheep/a7a2619d6ed2541338db4dca14a9af2f to your computer and use it in GitHub Desktop.
Save GreepTheSheep/a7a2619d6ed2541338db4dca14a9af2f to your computer and use it in GitHub Desktop.
Exit commands on Node.js with MariaDB backend
process.on('SIGINT', exit); // CTRL+C
process.on('SIGQUIT', exit); // Keyboard quit
process.on('SIGTERM', kill); // `kill` command
process.on('SIGWINCH', exit); // docker down or else idk
function exit() {
console.log("Exiting...");
DB.end().then(process.exit(0))
.catch(err=>{
console.error("MariaDB End connexion error:", err);
process.exit(1);
});
}
function kill() {
console.log("SIGTERM received, killing connexion...");
DB.end(true).then(process.exit(0))
.catch(err=>{
console.error("MariaDB End connexion error:", err);
process.exit(1);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment