What's New in Node.js 17

Ayooluwa Ayooluwa Isaiah on

Node.js v17.0.0, the latest major version of the popular JavaScript runtime, has just been released. It supersedes v16 in the Current release line of the runtime. V16 is now in line to be promoted to the long-term support (LTS) channel on October 26, 2021, as it’s an even-numbered release.

Despite being a relatively minor update, this release brings several refinements to the runtime, including more promisified APIs, JavaScript engine upgrades, and OpenSSL 3.0 support.

In this article, we’ll take a look at some of the major highlights from this release and the implications for Node.js developers.

New Promise-based APIs

Node.js continues to promisify its core APIs as part of its strategic initiative plan. In the last few major Node.js releases, Promise-based APIs were added for the dns, fs, stream, and timers modules.

In Node.js 17, this ongoing promisification work has been extended to the readline module, primarily used for accepting input from the command line. The new APIs are accessible via the readline/promises module.

The old way of utilizing the readline module in Node.js v16 and earlier involved using callback functions, as shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
// main.mjs
import readline from "readline";
import process from "process";

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

rl.question(`What's your name?`, (name) => {
  console.log(`Hi ${name}!`);
  rl.close();
});

As of Node.js 17, you can now use await when importing from readline/promises:

1
2
3
4
5
6
7
8
9
10
11
12
// main.mjs
import readline from "readline/promises";
import process from "process";

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

const name = await rl.question(`What's your name?`);
console.log(`Hi ${name}!`);
rl.close();

Stack Traces Now Include the Version of Node.js

When diagnosing a reported issue, a common question is: what version of Node.js executed the program?

Node.js 17 makes it easier to provide this information by including the version number at the end of a stack trace whenever an uncaught exception causes the process to exit:

1
2
3
4
5
6
7
8
9
10
11
12
13
file:///home/ayo/dev/demo/main.mjs:1
throw new Error("Uncaught exception");
      ^

Error: Uncaught exception
    at file:///home/ayo/dev/demo/main.mjs:1:7
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Node.js v17.0.0

If you’d rather omit this information in your program’s stack trace, you can use the --no-extra-info-on-fatal-exception command-line flag when starting your Node.js scripts.

OpenSSL 3.0 Support

Node.js 17 now supports the newly unveiled OpenSSL 3.0 release.

The aim is for the APIs in OpenSSL 3.0 to be compatible with those provided in previous OpenSSL versions. However, stricter restrictions on the allowable key sizes and algorithms mean there might be some ecosystem impact — especially for users still using small keys or older algorithms.

This impact is reflected in the error message ERR_OSSL_EVP_UNSUPPORTED in Node.js 17 when your application or its dependencies uses an algorithm or key size that is not allowed in OpenSSL 3.0.

You can use the --openssl-legacy-provider command-line flag to enable the OpenSSL 3.0 legacy provider as a temporary way to ease these restrictions.

V8 Is Upgraded to v9.5

As of Node.js 17, the v8 JavaScript engine has been updated to v9.5. The changes in this release are primarily aimed at expanding internationalization for dates and calendars as well as for the output of time zones. It also implements the WebAssembly Exception Handling proposal, designed to reduce overhead compared to current JavaScript-based workarounds.

Deprecations and Removals

As a major release, Node.js 17 also comes with a few deprecations and removals. A notable one is the deprecation of trailing slash pattern mappings which is unsupported in the import maps specification.

Upgrading to Node.js 17

You can download Node.js 17 to your computer using the appropriate link for your operating system and architecture provided on the Node.js download page. A better way to manage Node.js releases on your machine is to use a Node.js environment management tool like Volta, which allows you to install and switch between multiple Node.js versions seamlessly.

After installing the Volta CLI, run the command below to install the latest version of Node.js:

1
2
$ volta install node@latest
success: installed and set node@17.0.1 (with npm@8.1.0) as default

You can also install specific versions using the syntax below:

1
2
3
$ volta install node@lts # install latest lts version
$ volta install node@16.9.0 # install specific version 16.9.0
$ volta install node@12 # install the latest v12 release

When you install a Node.js release with Volta, it will co-exist with any other versions that you have already installed.

You can list the Node runtime versions in your toolchain using the command below:

1
2
3
4
5
6
7
8
9
$ volta list node
⚡️ Node runtimes in your toolchain:

  v14.8.0
  v14.17.5
  v16.7.0
  v16.8.0
  v16.9.0
  v17.0.1 (default)

Please see Volta’s online documentation for more details on how it works and what it can do.

Wrapping up

You can examine the complete list of bug fixes, new features, and other changes included in this release in the official Node.js v17 release notes.

To find out more about the Node.js project and how you can contribute, you can check out the list of Node.js open issues and Node.js contribution guidelines on the project’s GitHub repository.

Thanks for reading, and happy coding!

P.S. If you liked this post, subscribe to our JavaScript Sorcery list for a monthly deep dive into more magical JavaScript tips and tricks.

P.P.S. If you need an APM for your Node.js app, go and check out the AppSignal APM for Node.js.

Our guest author Ayo is a Software Developer by trade. He enjoys writing about diverse technologies in web development, mainly in Go and JavaScript/TypeScript. You can learn more about him through his blog.

5 favorite Javascript articles

10 latest Javascript articles

Go back
Javascript sorcery icon

Subscribe to

JavaScript Sorcery

A true sorcerer combines ancient wisdom and new discoveries. We'll provide you with both. Sign up for our JavaScript Sorcery email series and receive deep insights about JavaScript, error tracking and other developments.

We'd like to set cookies, read why.