Hey guys I am back with another blog post. In this post we will be discussing How to exit in Node.js?. We will be discussing the different sort of commands that we can use to exit out of node.js application i.e. to terminate the node.js process. Let’s start by seeing the different methods which are as follows:

METHOD-1

Call the global process object’s exit method:

METHOD-2

From the docs you can provide certain code in exit method:

METHOD-3

If you are in a Unix Terminal or windows command line and want to exit the node:

  • Press Ctrl + C twice, or
  • type .exit and press Enter, or
  • press Ctrl + D at the start of a line (Unix only)

METHOD-4

From the command line in Unix or Windows .exit is what you want::

OTHER USEFUL EXIT CODES

1 – Catchall for general errors
2 – Misuse of shell builtins (according to Bash documentation)
126 – Command invoked cannot execute
127 – “command not found”
128 – Invalid argument to exit
128+n – Fatal error signal “n”
130 – Script terminated by Control-C
255\* – Exit status out of range

This is the end of the post and you have successfully understood how to exit in Node.js. Thank you very much for reading this post and also please subscribe to our newsletter for receiving more posts like this.

A programmer scientist by the mind and a passionate blogger by heart ❤️. Fountainhead of Coding Shiksha Life motto: Live while you can! Teach & inspire while you could & Smile while you have the teeth.

Gautam Sharma

Founder , Coding Shiksha

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *