What new can you expect from Node.js in 2020?

Node.js turned 10 years old in 2019. The number of packages available in the npm registry has crossed the 1 million mark. Every year, the download volume of the Node.js platform itself increases by 40%. Another milestone for Node.js was that this project joined the OpenJS Foundation. Thanks to this, we can expect an improvement in the status and stability of the project, as well as, in general, positive developments in the field of interaction between members of the JavaScript community.



It is easy to see that in a short period of time, over a year, a lot of interesting things happened in the world of Node.js. Every year, Node.js is gaining momentum. We have no reason to rely on anything else in 2020.

In the next releases of Node.js we will find many interesting features. This material is dedicated to the most significant innovations of the platform that may appear in it in 2020.

Innovations Node.js 13


At the beginning of December 2019, at the time of writing this material, Node.js 13 is the latest version of this platform. There are already many new features and improvements with which you can start experimenting, preparing for the new year. Here is some of them:

  • ECMAScript modules.
  • WebAssembly support.
  • Diagnostic reports.
  • Full support for internationalization. In particular, we are talking about the formats of date, time, numbers, currencies.
  • Support for QUIC protocol.
  • Improving the performance of the V8 JavaScript engine.

Before we go into details about these features, we’ll talk about what can be expected in the areas of the release of new versions of Node.js and support for already released versions of the platform.

The process of releasing new versions of Node.js in 2020


A new major version of Node.js is released every 6 months. One in October, the other in April. They are called "current versions." At the time of this writing, the current version of Node.js is the 13th, released in October 2019.

Versions with odd numbers (v9, v11, v13) are released every October. They are relevant for a relatively short time, they are not considered ready for use in production. They can be considered beta versions of the platform. They are designed to test new features and changes that will fall into the next version of Node.js with an even number.

Versions with even numbers (v8, v10, v12) are released every April. After the release of such a version, the release of updates for the previous "even" version stops. Although these versions are much more stable than the "odd ones", active work on them continues for another 6 months. At this time, they can be considered as being in a release candidate state.

After the β€œeven” version is finalized within 6 months, it enters a new stage in its life cycle, turning into the LTS version (Long-Term Support, long-term support). LTS versions of Node.js are considered ready for use in production. Over the next 12 months, bug fixes, security updates, and other improvements are being released for these versions. All this is done taking into account the preservation of the operability of existing applications.

After the LTS stage, the Maintenance stage begins. Only critical bug fixes and security updates are released at this time. The escort stage lasts 18 months. After this time has passed, the corresponding version goes to the stage of the end of the life cycle (EOL, End-of-Life) and is no longer supported.


Node.js Version Life Cycle

The expected release plan for new versions of Node.js in 2020


In 2020, we can expect the following plan for the release of new versions of Node.js:

January-March 2020

  • The current version is 13.x, active work is underway on it.
  • Versions 10.x and 12.x are in LTS state.

April 2020

  • Version 14.x becomes current.
  • Work on version 13.x stops shortly after the release of 14.x.
  • Version 10.x is entering the maintenance phase.

October 2020

  • Version 15.x is released, which becomes current.
  • Version 14.x is entering the LTS phase.
  • Version 12.x goes into the maintenance phase.


Plan for the release of new versions of Node.js in 2020

Please note that the end of the Node.js 8 life cycle is scheduled for the end of 2019. The fact is that this version of the platform depends on OpenSSL-1.0.2, and the life cycle of this version of OpenSSL also ends at the end of 2019. Plan to migrate Node.js 8.x applications to Node.js 10.x or 12.x if you haven’t done so already.

ECMAScript Modules


In version 13.2.0 Node.js supports both CommonJS modules and the new standard ECMAScript modules (ES modules) without the need for any third-party tools. This means that developers can finally use the import and export instructions, the same ones that they probably already use when creating front-end projects in JavaScript. In addition, it is important to note that ES modules in Node.js work in strict mode by default. As a result, to enable this mode, you do not need to add "use strict"; to the beginning of each file "use strict"; .

 //  message async function sendMessage { ... } export { sendMessage }; //  index import { sendMessage } from "./message"; 

However, in order to inform Node.js that the developer uses ES-modules, something needs to be done. Here you can use one of the two most commonly used methods. The first of these is that the files are assigned the extension .mjs . The second is that the closest parent file package.json places the construct "type": "module" .

Everything is clear with the first approach - .js files are renamed to .mjs files. When using the second approach, in the root file package.json , or in package.json , placed in the folder containing ES modules, add the type property with the value module :

 {   "type": "module" } 

Another possibility regarding working with ES modules is to include them in the root file of the package.json project and to change the file extensions using CommonJS modules to .cjs .

Personally, it seems to me that using the .mjs or .cjs is not a particularly good idea. Therefore, I am pleased to see that to work with ES-modules it is enough to make changes to the package.json file.

Import WebAssembly Modules


Node.js now supports not only ES-modules, but also the import of WebAssembly-modules (Wasm-modules). A wasm module is a file that contains code in a portable binary format that can be parsed faster than similar JavaScript code and executed at a speed similar to native. Wasm modules can be created by developing source code in languages ​​such as C / C ++, Go, C #, Java, Python, Elixir, Rust, and many others.

Support for WebAssembly modules is still in an experimental phase. In order to enable this feature, you need to pass Node.js a special command line flag when starting the application:

 node --experimental-wasm-modules index.js 

Consider an example. Suppose we have an image processing library implemented as a Wasm module. To work with such a library in JS code, you can do this:

 import * as imageUtils from "./imageUtils.wasm"; import * as fs from "fs"; ( async () => {   const image = await fs.promises.readFile( "./image.png" );   const updatedImage = await imageUtils.rotate90degrees( image ); } )(); 

Here we imported the module and used the function available in it.

Wasm modules in Node.js can be imported using the new dynamic import() statement:

 "use strict"; const fs = require("fs"); ( async () => {   const imageUtils = await import( "./imageUtils.wasm" );   const image = await fs.promises.readFile( "./image.png" );   const updatedImage = await imageUtils.rotate90degrees( image ); } )(); 

WebAssembly System Interface


WebAssembly technology, like JavaScript, was developed with security in mind. Wasm code runs in a secure environment, sometimes called a sandbox. This allows you to protect the operating system in which it runs from such code. However, in some cases, Wasm modules running in the Node.js environment can only benefit from the ability to make system calls.

This is where the WebAssembly System Interface (WebAssembly System Interface, WASI) enters the scene. WASI is designed as a standard interface for accessing systems that run Wasm code. Such systems may include host applications, operating systems, and so on.

You can find a recent commit in the Node.js repository introducing initial WASI support. As a matter of fact, the WebAssembly system interface is one of the interesting features of Node.js, the appearance of which can be expected in 2020.

Diagnostic Report Support


Diagnostic reports are JSON documents intended for people that contain information about the operation of software mechanisms. Such information may include function call stacks, information about the operating system, data on loaded modules and other useful indicators aimed at helping to support applications. Similar reports can be created when unhandled exceptions, critical errors occur. They can be generated by signals from processes or using the new process.report API. Node.js can be configured so that diagnostic reports are saved in the specified folder using the specified file names.

Now this feature is experimental. To enable it, you need to pass Node.js a special flag when starting the application:

 node --experimental-report --report-uncaught-exception --report-filename=./diagnostics.json index.js 

Extending support for internationalization


Node.js 13.x includes the full version of the ICU ( International Components for Unicode ) library. ICU is a mature popular project. Among the many features of this library, support for formatting numbers, dates, currencies, and time output in a localized format can be noted. She is able to perform calculations related to time intervals, is able to compare strings and transcode texts from Unicode to other encodings and vice versa.

Some other new features of Node.js


Here are some more interesting features of Node.js, the appearance of which can be expected in 2020:

  • Support for QUIC protocol. QUIC is a modern Internet protocol with which you can establish reliable and productive communications between applications.
  • Improved support for Python 3. In 2020, we should be able to build Node.js modules and native modules using Python 3.
  • An updated version of the JS engine V8. Versions 7.8 and 7.9 of the V8 engine will provide increased application performance and Wasm support.
  • Stable API Worker Threads. The Worker Threads API allows you to parallelize intensive computing.

Dear readers! What do you most expect from the Node.js platform in 2020?


Source: https://habr.com/ru/post/479270/


All Articles