NodeJS : UnhandledPromiseRejection handling

May 11th, 2017 by Richy B. Leave a reply »

Are you programming Node JS Javascript and reached the dreaded:

(node:1984) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): xxxxx
(node:1984) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

but can’t figure out where the Promise is in NodeJS which is causing this? Just add the following bit of code near the top of your code (after the requires if used) which might help:

process.on('unhandledRejection', function(reason,promise) {
console.log('unhandledRejection', reason);

This post is over 6 months old.

This means that, despite my best intentions, it may no longer be accurate.

This blog holds over 12 years of archived content - during that time, I may have changed my opinion of something, technology will have advanced (and old "best standards" may no longer be the case), my technology "know how" has improved etc etc - it would probably take me a considerable amount of time to update all the archival entries: and defeat the point of keeping them anyway.

Please take these posts for what they are: a brief look into my past, my history, my journey and "caveat emptor".

Comments are closed.

%d bloggers like this: