How to exit the program in Node.js?

When fatal error happened, we'd like to kill the program. How to exit the program in Node.js?

asked Oct 15, 2015 by Eric Z Ma (44,280 points)

1 Answer

 
Best answer

You can use:

process.exit()

Here, "process" is a global process object. exit method ends the process.

process.exit([code])

Ends the process with the specified code. If omitted, exit uses the
'success' code 0.

To exit with a 'failure' code:

process.exit(1);

The shell that executed Node.js should see the exit code as 1.

answered Oct 15, 2015 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...