noddy asked this 4 years ago

How to exit a Node.js script programmatically?

How do I exit a Node.js script gracefully when a condition is met?


Best Answer by mkbaines 4 years ago

To exit with success (0),

process.exit(0);

To exit with failure (1),

process.exit(1);

Default value is 0 (success), so for success you can just

process.exit();

Refer:

https://nodejs.org/docs/v0.5.4/api/process.html#process.exit