0

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 1

1

If it's graceful then yeah. If it's something like uncaughtException then it's not recommended.

According to node docs:

SIGTERM and SIGINT have 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:

uncaughtException should be used to perform synchronous cleanup before shutting down the process.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.