The Node.js team has  announced the release of a new major version — Node.js 15 🎉!

While a new release is always exciting, some folks are wondering what it means for them.

How do the changes affect me, and what should I do before updating?

What are the new features and their practical use cases?

Aside from a single, but important, breaking change, Node.js 15 is mainly about new features. Updating from older Node.js versions should therefore be fairly straightforward. Keep in mind that Node.js 15 won’t go into LTS, more on that below.

Read on to find out what the new features are and how you can use them in your projects.

Unhandled rejections are thrown

Prior to Node.js 15, you would get the following error when a promise would reject without being caught anywhere in the promise chain:

(node:1309) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
(node:1309) [DEP0018] 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.

You’re probably familiar with this message. This warning has been around since Node.js 6.6, released over 4 years ago. The team behind Node.js has finally decided it was time to act on the deprecation warning.

From version 15 and onwards, Node.js will raise an uncaught exception and terminate the application. This can be a nasty surprise in production if you decide to update Node.js without being aware of this change.

By adding a global handler of the unhandledRejection  event, you can catch unhandled rejections and decide how you want to proceed. The following code will simply log the event and keep the application running, similar to the behaviour of earlier Node.js versions:

// Global handler for unhandled promise rejections
process.on('unhandledRejection', (reason, promise) => {
    console.log('Unhandled Rejection at:', promise, 'reason:', reason);
    // Decide whether to:
    // 1\. Do nothing and keep the application running or
    // 2\. Exit with `process.exit(1)` and let a process manager automatically restart the application
});

#blog

Node.js 15 Is Out! What Does It Mean for You?
1.40 GEEK