Node.js 13 and beyond

20 april 2020 om 10:24 by ParTech Media - Post a comment

2019 was a pretty exciting year for Node.js developers. The year marked the launch of the latest Node.js version, Node.js 13. Thanks to this launch, Node.js has now made a successful move to Long Term Support. That means, in addition to versions 10 and 8, Node.js 12 stands out as one of the latest Long Term Support releases for the server.

The Node.js 13 comes with plenty of new offerings. Powered by a bunch of new features like the Full ICU, Heap Dump Capabilities, and the Worker API, Node.js 13 will now offer quicker start-up and more consistent heap limits.

In this article, we’ll discuss these features in detail while also shedding some light on what other features you can expect in 2020

Features and changes

While the version 13 comes with many new changes and features, our favorites include:

V8 Update: The new version of Node.js 13 comes with a version update for the JS engine. The latest V8 version of Javascript’s engine isn’t just more stable, but it also comes with new language options and ensures better performance.

Full ICU: This version comes enabled with the Full ICU. Thanks to this default feature, Node.js now works with a more diverse set of languages from the beginning.

Stable Workers API: The Workers API in Node.js 13 is much more stable when compared to its predecessors. This ensures glitch-free performance with minimum lags.

Now that you have a basic idea of what to expect in this new version, let’s take a closer look at the features.

Workers API

While the Workers API was already available in Node.js version 12, it wasn’t as stable as the latest version. Node.js now performs exceptionally well with both single-threaded loops and other use cases with multiple threads. The results are faster and there are barely any interruptions.

Here’s how the new API looks like:

const workers = require('worker_threads');

if (workers.isMainThread) {
  const worker = new workers.Worker(__filename, {
    workerData: 41 
  });

  worker.on('message', (response) => {  
    console.log(response);
 }); 
} 
else {
  workers.parentPort.postMessage(workers.workerData + 1 )
}

Source: https://developer.ibm.com/technologies/node-js/blogs/nodejs-13-is-out-heres-what-it-means-for-you/

Better Platform Support

Node.js has embraced the newer features of C++ to leverage compiler optimization functions. The result: enhanced and uncompromised security. The latest Node.js 13 will need version 10 and higher versions for developing tools and version 7.2 and higher versions for using the AIX OS.

The platform is also supporting Python 3 for creating Node.js apps. That being said, you can still use Python 2 if your system has both versions.

Supports Default ICU

The latest Node.js release is powered by default full ICU. Although the previous version has supported ICU for a while, developers still needed to complete extra steps for enabling the data required for processing an entire set of languages. With the default ICU support in place, this will no longer be an issue.

This is better demonstrated with the following example. Say for instance you run this command:

console.log(new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8)));
console.log(new Date(0).toLocaleString("el",{month:"long"}));
console.log(new Date(157177E7).toLocaleString("zh",{year:"numeric",day:"numeric",month:"long"}));

Here, es stands for Spanish, zh stands for Chinese, and el stands for Greek.

If you run this code on Node.js 12, you will get the following output:

bash-4.2$ node test2.js

January
December
October 22, 2019

If, however, you run the same code on Node.js 13, your output will be:

bash-4.2$ node test2.js

enero
Δεκεμβρίου
2019年10月22日

As evident from this example, Node.js can now interpret and process multiple languages without having you to tweak anything manually. This makes it easier for developers who operate the system from different corners of the globe.

V8 is Upgraded

The new version is now upgraded to support version V8 7.8. This latest version of JS engine will improve the overall performance by continuously tweaking the runtime and the language.

Highlights Programming Errors

Node.js 13 also highlights programming mistakes better. When you pass the validation function assert.throws () or assert.rejects (), an assertion error comes up instead of the usual error message. This will help define the programming issue better.

You are likely to get a similar assertion error if you use a constructor function for validating the errors in assert.throw () or assert.reject.

What to Expect in 2020?

With new releases scheduled in April and October, here's what you can expect from the latest versions.

img

Diagnostic Reports

Formatted in json, Diagnostic reports are a short description of the different process details including (but not limited to), information about the operation system, module data, call stack data, and more. These details can be categorized as reports with a process.report API. After this, the developer can configure Node.js to save diagnostic reports against a specific file name. At the time of writing this article, this feature is still being experimented.

ICU Support

The v13.x version of Node.js features the complete ICU. For the uninitiated, ICU is a leading globalization database that comes with multiple features. Key takeaways include extended support to tweak numbers, dates, and currencies, a feature to perform time calculations, a tool to conduct string comparison, and a tool to convert text between different characters.

Additional Upgrades

Here are a couple of other upgrades we are expecting:

  • Support for QUIC Protocol: This will boost the performance and stability of the connected tools and applications.
  • Better Support for Python Version 3: This year, we are expecting a feature that’ll help build Node.js along with a bunch of other native modules with Python’s 3+ versions.
  • Tweaks with the Javascript Engine: In 2020, many developers are also expecting a better performing and stable js V8 engine.
  • Worker Threads: While Node.js has already improved in the API front, we are expecting similar improvements that’ll render some degree of stability to the Worker Thread API.

Bottom Line

Given the perks this new version comes with, we are quite optimistic about the upcoming releases and their many new features that'll address the minor pain points in the existing version.