What's the difference between abort() and exit() in Node?

process.abort() stops the process immediately.

process.exit([exitCode]) method instructs Node.js to terminate the process as quickly as possible. You can also specify an exit code.

For exit codes:

  • 0 means the process was exited successfully.
  • 1 means it ended abnormally.
  • When omitted, 0 is the default value.

The process.exit() method instructs Node.js to terminate the process as quickly as possible with the specified exit code.

If the code is 0 mean exists as success case.

if the code is 1 mean exists as failer case.

And

The process.abort() method causes the Node.js process to exit immediately and generate a core file.

Nothing more difference I have seen except those


Calling process.exit() will force the process to exit as quickly as possible even if there are still asynchronous operations pending that have not yet completed fully, including I/O operations to process.stdout and process.stderr.

The proper recommended way to exit from process is to set the exit code and allow process to exit naturally because calling process.exit() forces the process to exit before any additional writes to stdout can be performed.

process.exitCode = 1;

If it is necessary to terminate the Node.js process due to an error condition, throwing an uncaught error and allowing the process to terminate accordingly is safer than calling process.exit().

The process.abort() method causes the Node.js process to exit immediately and generate a core file.

Tags:

Node.Js