What’s New In Node.js 15?

What's new in node.js 15

Modern web applications are developed with many popular frameworks like Angular JS,  bootstrap and so on. These frameworks are based on popular Javascript frameworks. But when it comes to developing server-based applications, Node.js comes into the focus. It is also based on the JavaScript framework but used for developing server-based applications. In 2020, Node.js turned 11 years old, and the number of packages available on npm crossed one million. Downloads for Node.js itself continue to rise, growing 40% year over year. A lot has happened in a relatively short amount of time! Each year the Node.js community has gained momentum, and 2020 shows no signs of slowing down. There are lots of interesting features being explored for the next major releases of Node.js 15. Here we will see some major features in node.js 15.

New Features In Node.js 15-

1. N-API Version 7-

Node.js 15 eases the creation, build and support native modules.  It comes with N-API version 7 which includes some extra methods to work with array buffers-

napi_status napi_detach_arraybuffer(napi_env env, napi_value arraybuffer)
napi_status napi_is_detached_arraybuffer(napi_env env, napi_value arraybuffer, bool* result)

2. npm 7-

It is a major release that comes with new features including workspaces and a new package-lock.json format. Npm 7 also includes yarn.lock file support. There is a new change in the latest version with npm 7 – peer dependencies are installed by default. Npm team has worked to minimize potential disruption to existing projects because of the switch to automatically installing peer dependencies, if you face any problem, you can sue the –legacy-peer-deps flag at install time as a workaround to revert to the previous behavior. You can set it in the environment or npm config files.

3. AbortController-

The latest version of nodejs features an experimental implementation of AbortController. AbortController is a global utility class used to signal cancelation in selected Promise-based APIs, based on the AbortController Web aPI-

const ac = new AbortController();
ac.signal.addEventListener('abort', () => console.log('Aborted!'), { once: true });
console.log(ac.signal.aborted);  // Prints True

Here, the abort event is emitted when ac.abort() is called. The AbortController will trigger the abort event once. Event listeners should use the { once: true } option (or EventEmitter API equivalent- once()) to check that the event listener is removed once the abort event is handled.

4. QUIC (experimental)-

It is a new UDP- based transport protocol which is underlying transport protocol for HTTP/3. QUIC features inbuilt security with TLS 1.3, flow control, error correction, multiplexing and connection migration. This latest version of node.js  comes with experimental support QUIC that can be allowed by compiling Node.js with –experimental -quic configuration flag. The Node.js QUIC implementation is exposed by the core net module:

const { createQuicSocket } = require(‘net’);

5. Updated handling of rejections-

Till the previous version of Node.js, if there was an unhandled rejection, you will get a warning regarding rejection and a deprecation warning.

For example, 

new Promise((resolve, reject) => {

This would result in following deprecation message:

(node:31727) UnhandledPromiseRejectionWarning: error
(node:31727) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:31727) [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.

To avoid these warning messaging, handle rejection with a catch block: 

new Promise((resolve, reject) => {
}).catch((error) => {});

As of Node.js 15, the default behavior has changed to:

          triggerUncaughtException(err, true /* fromPromise */); ^
[UnhandledPromiseRejection: 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(). The promise rejected with the reason "error".] {

This change is made to meet the community expectations and to help surface problems that would else be hard to detect an debug. It inlines the behavior of unhandled rejections with that for unhandled exceptions where throw behavior being useful. Node.js lets you to configure the default behavior for unhandled rejections through the –unhandled-rejections flag. If you want to revert to the previous default, just add the below command line: –unhandled-rejections=warn or through the 

NODE_OPTIONS evironment variable export 

Aso, you can handle rejection by adding an unhandledRejection listener:

process.on('unhandledRejection', (reason, promise) => {
  // do something

Know the- 6 Awesome Things You Can Do With NodeJS.

Final Words- 

Nodejs is continuously gaining popularity and is not showing signs of slowing down. Now in 2020, node.js came with the latest version v15 with the above amazing features. If you’re thinking about developing a software with Node.js, consider these new features of version 15. You can hire skilled node.js developers of solace team for an effective development with latest features. Consult with solace experts and get a free quote for node.js development. We will be happy to help you.

Related Post