Node.js by Example: Exit

Use process.exit to immediately exit with a given status.

queueMicrotasks will not be run when using process.exit, so this console.log will never be called.

queueMicrotask(() => console.log("!"));

Exit with status 3.

process.exit(3);

You can see the status in the terminal.

$ node exit.js
$ echo $?
3

Note that the ! from our program never got printed.