Reputation: 15684
How can I stop my node server if a promise fails ?
myPromise.then(res => {})
.catch(err => {
throw "bad error" // I want to stop the program like I in the synchronous senario. Not get unhandled promise exception
})
Upvotes: 0
Views: 39
Reputation: 232
Call the exit()
function on the global process
object with a non-zero exit code.
myPromise
.then((res) => {})
.catch((err) => process.exit(1));
Read more here: https://nodejs.org/api/process.html#process_process_exit_code
Upvotes: 1