a blog for those who code

Saturday, 6 August 2016

How to exit in Node.js

In this post we will show you how to exit from Node console or exit from the node.js application. Node.js has a global process object which has exit method, which can be called to exit from the node.js. Process object's methods and properties provides information about the application or the environment in which it is running.

The exit method terminates the process with the specified code as shown below.

process.exit([code])

In the above method, code is passed as a parameter which is an integer value whose default value is 0. Now to exit with a failure code you will specify the code like :

process.exit(1);

ALSO READ : Process Object in NodeJS

One thing to note that process.exit() will exit the program even if there are asynchronous operations pending that have not completed.

If you are in Windows Command Line or Unix Terminal and want to exit the Node REPL you can type

1. CTRL + C Twice (CTRL + C & CTRL + C)
2. Type .exit and press Enter 

ALSO READ ; Keyboard Control And Commands in Node.js (REPL)


Please Like and Share the CodingDefined Blog, if you find it interesting and helpful.

No comments:

Post a Comment

Contact Us

Name

Email *

Message *

Sponsers

Best Hosting Plans

CC License