How to exit in Node.js


Question

What is the command that is used to exit? (i.e terminate the Node.js process)

1
1693
8/14/2018 3:09:53 AM

Accepted Answer

Call the global process object's exit method:

process.exit()

From the docs:

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 should see the exit code as 1.

2144
2/29/2016 7:32:19 PM

From the official nodejs.org documentation:

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);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon