How can I exit a nodeJS script from within the script?

Right now I have a nodeJS script that sets up a database for me. Whenever I run it in my command line, I need to ctrl-C to exit the script. I’m assuming that there is some kind of command within nodeJS to have it exit on its own when it’s done, but I can’t seem to find any such command by doing searches on the interwebz. Does anybody happen to know if this is possible, and if so, what the command is?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

you can exit the script by calling process.exit() (see

Solution 2

you should be using process.exit(). You can pass any status also which will be displayed on the console log.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply