javascript

What's New in Node.js 17

Ayooluwa Isaiah

Ayooluwa Isaiah on

What's New in Node.js 17

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// main.mjs
2import readline from "readline";
3import process from "process";
4
5const rl = readline.createInterface({
6  input: process.stdin,
7  output: process.stdout,
8});
9
10rl.question(`What's your name?`, (name) => {
11  console.log(`Hi ${name}!`);
12  rl.close();
13});

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

1// main.mjs
2import readline from "readline/promises";
3import process from "process";
4
5const rl = readline.createInterface({
6  input: process.stdin,
7  output: process.stdout,
8});
9
10const name = await rl.question(`What's your name?`);
11console.log(`Hi ${name}!`);
12rl.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:

1file:///home/ayo/dev/demo/main.mjs:1
2throw new Error("Uncaught exception");
3      ^
4
5Error: Uncaught exception
6    at file:///home/ayo/dev/demo/main.mjs:1:7
7    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
8    at async Promise.all (index 0)
9    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
10    at async loadESM (node:internal/process/esm_loader:88:5)
11    at async handleMainPromise (node:internal/modules/run_main:65:12)
12
13Node.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$ volta install node@latest
2success: 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$ volta install node@lts # install latest lts version
2$ volta install node@16.9.0 # install specific version 16.9.0
3$ 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$ volta list node
2⚡️ Node runtimes in your toolchain:
3
4  v14.8.0
5  v14.17.5
6  v16.7.0
7  v16.8.0
8  v16.9.0
9  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.

Share this article

RSS
Ayooluwa Isaiah

Ayooluwa Isaiah

Ayo is a Software Developer by trade. He enjoys writing about diverse technologies in web development, mainly in Go and JavaScript/TypeScript.

All articles by Ayooluwa Isaiah

AppSignal monitors your apps

AppSignal provides insights for Ruby, Rails, Elixir, Phoenix, Node.js, Express and many other frameworks and libraries. We are located in beautiful Amsterdam. We love stroopwafels. If you do too, let us know. We might send you some!

Discover AppSignal
AppSignal monitors your apps