Skip to content

Instantly share code, notes, and snippets.

@ededejr
Last active February 6, 2024 05:21
Show Gist options
  • Save ededejr/78963eb0e8a1410ab507fb1de5d13108 to your computer and use it in GitHub Desktop.
Save ededejr/78963eb0e8a1410ab507fb1de5d13108 to your computer and use it in GitHub Desktop.
a utility function for executing callbacks on process exit in nodejs
function onProcessExit(callback: () => void): void {
[
"SIGINT",
"SIGTERM",
"SIGHUP",
"SIGBREAK",
"unhandledRejection",
"uncaughtException",
].forEach((signal: string) => {
process.on(signal, () => {
callback();
process.exit(0);
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment