Node.js process.exitCode Property
There are two ways that are generally used to terminate a Node.js program which are using process.exit() or process.exitCode variable. In this post, we have discussed about process.exitCode variable. It is an integer that represents the code passed to the process.exit() function or when the process exits on its own. It allows the Node.js program to exit naturally and avoids the Node program to do additional work around event loop scheduling, and it is much safer than passing exitcode to process.exit().
process.exitCode = value
Here value means exitcode value.
Example 1: One way is to pass exitcode value to process.exit() function. Exit code 1 is used when unhandled fatal exceptions occur that was not handled whereas Exit code 0 is used to terminate when no more async operations are happening.
Example 2: Another way is to set process.exitCode value which will allows the Node.js program to exit on its own without leaving further calls for the future.