Languages
[Edit]
EN

Node.js - exit from program (programmatically)

0 points
Created by:
Nathanial-Donald
344

In this article, we would like to show you how to exit from program in Node.js.

Quick solution:

process.exit(0);

Note:

Default value of the exit code is 0 and means success.

 

Introduction

The process module provides exit() method that allows you to programmatically exit from a Node.js program.

When Node.js executes the method, the process is immediately forced to terminate, which means that any callback function that's pending, any request still being sent, processes writing etc. is going to be ungracefully terminated right away.

Practical example

You can pass an integer that signals the operating system the exit code:

process.exit(0);

The default value of the exit code is 0 and means success.

Any different exit codes have different meaning which you might want to use in your system.

Example:

process.exit(1);

Meaning:

Uncaught Fatal Exception: There was an uncaught exception, and it was not handled by a domain or an 'uncaughtException' event handler.

References

Native Advertising
ūüöÄ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

‚̧ԳŹūüíĽ ūüôā

Join