In Node.js How can I stop the script execution, successfully write an error message to the console, and then exit the script?

  abort, console, exit, node.js, windows

I’m running Node.js using VS Code on Windows.

Upon detecting an error condition, how can I completely stop the execution of the script at that point, except for writing a final error message to the console?

I would need to wait until there is a confirmation that the error message has been successfully displayed to the user, and then completely exit the rest of the script without any further execution of the the code past the successful console write?

Source: Windows Questions