How to exit a Node.js script

process exit

Normally a Node.js script stops running when it reaches the end of the script and when there are no more event handlers waiting for events. What if you want the script to stop earlier?

It's quite easy.

The built-on process module has a method called exit:

examples/node/process_exit.js

process.exit(-1);

Comments

ctrl+C twice

or type:

.exit


nice


It was just what I was looking for. Thank you very very much

Other pages

argv - raw command line arguments in Node.js
Node.js
How to get system information of a file or directory in Node.js (stat)

Author

Gabor Szabo (szabgab) Gabor Szabo