Node.js 16 is released!

Node.js 16 has just been released, and the new version includes such new features and improvements as rebuilt Apple Silicon binaries and V8 version 9.0. Node.js 16 will also include a Mac installer, delivered as a thick binary file, and will include Intel and ARM architecture files. An important enhancement in Node.js 16 is also the addition of several additional stable APIs.

You can download the latest release from here. To boot, you can also use Node Version Manager on UNIX to install Node.js using nvm install 16. And here is the change log for Node.js 16.

Later in this article, we'll take a more in-depth look at some of the new features that the developers have introduced in version 16.

V8 update

The new version of the V8 JavaScript engine, or V8 9.0, gives us many performance-related improvements. Moreover, with this update, Node.js is up to date with the latest JavaScript features. The version that Node.js 15 used, on the other hand, was V8 8.6.

This update adds regex match indexes. This function allows you to read the beginning and end indices of the captured string. Such an array created from the previously mentioned indexes is available through the .indices property when the regular expression has the /d flag.

Here is a code example from the official Node.js 16 post:

> const matchObj = /(Java)(Script)/d.exec('JavaScript'); undefined > matchObj.indices [ [ 0, 10 ], [ 0, 4 ], [ 4, 10 ], groups: undefined ] > matchObj.indices[0]; // Match [ 0, 10 ] > matchObj.indices[1]; // First capture group [ 0, 4 ] > matchObj.indices[2]; // Second capture group [ 4, 10 ]

More information on the new V8 can be found here.

New API

In Node.js 16, a new API is introduced - it is called the Timers Promises API. It provides a set of timer functions that return Promise objects. So there is then no need to use util.promisify().

Here is a code example from the official post on Node.js 16.

import { setTimeout } from 'timers/promises'; async function run() { await setTimeout(5000); console.log('Hello, World!'); } run();

This API has already been added in version 15 - but this time it is promoted from an experimental feature to a stable feature.

Apple Silicon w Node.js

As we mentioned earlier, Node.js 16 will be the first version of this runtime environment to include pre-made binaries for Apple Silicon. Separate files for the Intel architecture, darwin-x64, and for the ARM architecture, darwin-arm64, are provided here.

The macOS installer will include both binaries.

Other features

In Node.js, features are added on an ongoing basis. That's why, many of them that are available in 16 were already available in version 15. Here are some:

  • An experimental implementation of the Web Crypto API
  • npm 7
  • Stable implementation of AbortController, based on AbortController Web API
  • Stable implementation of Source Maps v3

Support

The new release of Node.js also becomes the next LTS, or Long Term Support, release. Node.js 12 will have support until April 2022, 14 will have support until April 2023, and Node.js 10 will only be supported until the end of April 2021.

You can find more details here.

The original article in Polish can be found here.

01 May 2021