What is the command that is used to exit in Node.js?
What is the command that is used to exit in Node.js?
336
29-Apr-2023
Updated on 01-May-2023
Aryan Kumar
01-May-2023In Node.js, the command to exit a program is process.exit([code]). The process.exit() method exits the current Node.js process with an optional exit code.
The code parameter is an integer that represents the exit code. The exit code can be used to indicate the reason for the process exit. A value of 0 indicates successful termination, while non-zero values indicate an error or other non-successful exit.
Here's an example of how to use process.exit() to exit a Node.js program:
In this example, we use process.argv to check if the command line argument is "exit". If it is, we print a message and exit the program using process.exit(). If it isn't, we continue with the rest of the program.