REPL(Command Line)
Press ctrl + c
twice
Type .exit
and press enter
Script File
process.exit(code)
Node normally exits with code 0 when no more async operations are pending.
process.exit(1)
should be used to exit with a failure code.This will allow us to infer that node didn't close gracefully and was forced to close.
There are other exit codes like
3 - Internal JavaScript Parse Error ( very very rare)
5 - Fatal error in v8 javascript engine
9 - Invalid argument
For full list see node exit codes