Regardless of whether an exit is graceful or not, is there a way to run a MySQL (asynchronous) function before the program closes in Node.JS?
1 Answer
If it's graceful then yeah. If it's something like uncaughtException then it's not recommended.
According to node docs:
SIGTERMandSIGINThave default handlers on non-Windows platforms that resets the terminal mode before exiting with code 128 + signal number. If one of these signals has a listener installed, its default behavior will be removed (Node.js will no longer exit).
I.e. you can add your own handlers to those two events, and then just call process.exit() when you're done.
Also from the same page:
uncaughtExceptionshould be used to perform synchronous cleanup before shutting down the process.