What’s New In Node.js 17?

What's New In Node.js 17

Latest version of Node.js has been officially released. Node.js is now officially available to users, contributors and app developers also. It supersedes Node.js 16 in terms of the current release line of this runtime and now it got promoted to LTS or long term support channel on 26th October. Rather than being a minor update, this release brings some refinements to the runtime, including more promisified APIs, Javascript engine upgrades and OpenSSL 3.0 support. Here we’ll discuss the latest release of Node.js 17 features. Let’s get started.

Also know the amazing Node.js security best practices at- Top 10 Node.js Security Best Practices

What’s New In Node.js 17?

1. New Promise-based APIs-

Node.js promisify its core APIs as a part of its strategic initiative plan. In Node.js 17, this ongoing promisification work is extended to the readline module, mainly used to accept input from command line. New APIs are accessible through readline/promises module. Old way of using readline module in Node.js v16 and earlier involved using callback functions as-

// 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();
});

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

// 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();

2. Stack Traces-

Stack traces are important for node.js development companies and each common user of NodeJS runtime. It helps to detect errors affecting an app. Also it reveals the points that causes the errors. In this latest release , Node.js version will be present at the end of stack trace, especially when fatal exceptions force the process to exit. It’s helpful to have this capacity naturally because when somebody analyzes revealed errors, they’ll definitely need to discover the version of Node.JS they’re using. Node.js 17 has a command-line option that allows users and programmers to avoid extra information they don’t require. This line goes “–no-extra-info-on-fatal-exception.”

3. OpenSSL 3.0-

Now, node.js includes OpenSSL 3.0, particularly quictls/openssl, upgraded from OpenSSL 1.1.1.    OpenSSL 1.1.1 will reach the end of support on 2023-09-11, means before proposed End of life date for Node.js 18. Hence, it has been decided to include OpenSSL 3.0 in Node.js 17 to provide time for user testing and feedback before the next LTS release. Among all of the new features in OpenSSL 3.0 is the introduction of providers, of which FIPS provider that can be enabled in Node.js. OpenSSL 3.0 should be mostly compatible with those provided by OpenSSL 1.1.1, we can anticipate some ecosystem impact because of strict restrictions on the allowed algorithms and main issues.

In app with Node.js, if you hit ERR_OSSL_EVP_UNSUPPORTED error, it is somehow similar to that your app or module you’re using is using an algorithm or key size that is no longer allowed by default with OpenSSL 3.0. New command line option, –openssl-legacy-provider, has been included to revert to the legacy provider as a temporary workaround for strict restrictions..

For example-

$ ./node --openssl-legacy-provider  -p 'crypto.createHash("md4")'

Hash {
  _options: undefined,
  [Symbol(kHandle)]: Hash {},
  [Symbol(kState)]: { [Symbol(kFinalized)]: false }
}

4. V8 Is Upgraded To v9.5-

Node.js came with an updated V8 engine of Javascript to V8 9.5 in Node.JS 17. If you’re working with Node.js 16, programmers can rely on V8 9.4 meaning that latest one available on the previous version of runtime. Apart from performance-related tweaks and improvements, this new version brings some extra supported types for “Intl.DisplayNames” API and Extended options for “timeZoneName” in another API which is – “Intl.DateTimeFormat”.

5. Deprecations And Removals-

Node.js 17 comes with some removals and deprecations. Important one is deprecation of trailing slash pattern mappings that is not supported in the import maps specification.

6. LTS For Node.js 16-

Creators of Node.js will promote v16 for LTS. Lots of node.js  development companies believe that it is a significant milestone. Lots of users who’re working on production deployments, will only use Node.js LTS versions. Meaning that some features will be available for first time in the LTS release line. 

Corepack- script that fills the gap between Node.js projects, Node.js 16 and package managers should come in handy during development. Simply, Corepack developers can use pnpm and Yarn without installing them. The javascript engine used in Node.js 16 is V8 9.4. With this upgrade, the javascript language provides more features. Here are some of the features Node.js 16 boasts-

  • “Array.prototype.at” available from V8 9.2
  • Errors with cause available from V8 9.3
  • ECMAScript RegExp Match Indices from V8 9.0
  • “Object.hasOwn” available from V8 9.3

Some other new features of Node.js 16 LTS include Experimental web streams API and npm 8.

How To Upgrade To Node.js 17?

Download Node.js 17 using the appropriate link for operating system and architecture provided on Node.js download page. Best way to manage Node.js releases is to use Node.js environment management tools such as Volta, that allows you to install and seamlessly switch between various Node.js versions. After completion of installing Volta CLI, run below command to install the latest version.

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

Also, you can install particular version by using below syntax-

$ 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 Node.js release with Volta, it will co-exist with other versions that are already installed. List the Node runtime versions in your toolchain with following command:

$ 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)

Wrap Up-

Each new version comes with updated features and improvements. So before you start development, it is better to know the latest updations in the Node.js versions. If you are planning to use Node.js for your next project, have a detailed knowledge of the Node.js 17 features and improvements. You can consult with Solace experts and also hire skilled Node.js developers from the Solace team for effective development. Connect with Solace and get a free quote for Node.js development. We will be happy to help you. 

Related Post