Friday, November 12, 2021

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.


No comments:

Post a Comment