There multiple ways to exit a nodejs process with examples
NodeJS REPL Exit
REPL is an Node Command tool to execute node commands
Following is an command to exit NodeJS process
- First way, Select Ctrl + C two times two times
- Another way using type
.exitand click enter
The above two ways works in Linux, Unix and Windows
For Mac, You can use Ctrl + D to exist
How to exit Nodejs Process using API programs?
In Programs, Nodejs exit process called in two ways
one way by calling process.exit() manually. Another way, It calls automatically when there are no pending tasks to process by event loop.
Nodejs contains global
process object that contains
Here is an syntax.
code is an optional integer value, default is zero, that means success. Code=1 is an failure
For success, call process.exit(0) method. This executes normally when no asynchornous operations are in pending. For failure, call process.exit(1) method.
Since process is an instance of EventEmitter, calling process.exit() method exhibit the exit event, that terminates all work including asynchronous operations still in progress.
Nodejs process exit codes
Nodejs provides Process’s exit method has following error codes
|1||Uncaught fatal failures|
|2||Un reserved, can be used for bash|