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:
As of Node.js 17, you can now use await
when importing from
readline/promises
:
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:
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:
You can also install specific versions using the syntax below:
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:
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.