Search for '{{search_term}}'

How to exit a Node.js script

CMOS is the Code-Maven Open Source podcast that also includes video interviews. Subscribe to this feed RSS feed with your Podcast listener app or via iTunes iTunes.

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

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus