By David Neal

Translation: Crazy geek

Original text: developer.okta.com/blog/2019/1…

Reproduced without permission

In 2019, the 10th year of Node.js, the number of packages available on NPM has surpassed 1 million. Downloads of Node.js itself continue to grow, up 40 percent year over year. Another important milestone was node.js’ recent accession to the OpenJS Foundation, which promises to improve the health and sustainability of the project and improve collaboration with the entire JavaScript community.

As you can see, a lot has happened in a short time! The Node.js community is still thriving and shows no signs of slowing down even in 2020.

The next major release of Node.js is exploring more interesting features. In this article, I’ll look at some of the most important updates to the Node.js community to look forward to in 2020.

What’s new in Node.js 13?

The latest version of Node.js at the time of this writing is 13. There are already many features and updates that can be trialled before 2020. Here are some takeaways:

  • ECMAScript module
  • WebAssembly support
  • Diagnostic report
  • Full internationalization support for date, time, number, and currency formats
  • Support for QUIC protocol
  • V8 JavaScript engine performance update

Before diving into these details, let’s take a look at our expectations for the Release schedule of Node.js.

The Node.js release process for 2020

New major versions of Node.js will be released every six months, in April and October. The major version involved is called the current version. As of this writing, the current version of Node.js is 13, which was released in October 2019.

Odd-numbered versions (v9, V11, and V13, for example) are released in October each year and have a short lifespan, making them unsuitable for production environments. You can think of odd-numbered versions as beta versions. They are used to test new features and changes in the next even-numbered release of Node.js.

Even-numbered versions (such as V8, V10, and V12) are released each April. After release, the last odd-numbered version will stop updating. Although it is more stable than the odd-numbered version, active development will continue over the next six months. Think of the first six months as the “release candidate” phase.

Once the even-numbered version passes the six-month test, it will enter a new phase called “long Term support” (LTS). The LTS phase is considered ready for production. Over the next 12 months, bug fixes, security updates, and other improvements will be made to the LTS version without breaking any existing programs.

After LTS, there is a final “maintenance” phase. The Node.js version will only receive critical bugs and security fixes during maintenance. After 18 months of maintenance, it is considered to be at the end of its life (EOL) and is no longer supported.

The expected 2020 release schedule

We should expect to see the following release schedule in 2020.

From January to March 2020

  • 13. X isThe currentVersion, and is under active development
  • 10.x and 12.x are LTS

In April 2020

  • 14. X releases and becomesThe currentversion
  • After 14.x is released, work on 13.x stops immediately
  • 10. X Enters maintenance

In October 2020

  • 15.x is released and becomesThe currentversion
  • 14. Enter the LTS x
  • 12. X Enters maintenance

! [New node.js feature release schedule for 2020](

Note: Since the EOL of Node 8.x relies on OpenSSL-1.0.2, which ends at the end of 2019, the EOL of Node 8.x is planned for the end of 2019. You should start planning to migrate 8.x applications to 10.x or 12.x.

Support for ECMAScript modules

As of V13.2.0, Node.js supports both traditional CommonJS modules and the new standard ECMAScript (ES) modules. This means that you can finally use import and export syntax that you might already be able to use in a browser. It is also important to note that the ES module in Node.js has JavaScript strict mode enabled by default, and you don’t have to specify Use Strict at the beginning of every file.

// message file
async function sendMessage {... }export { sendMessage };

// index file
import { sendMessage } from "./message";
Copy the code

But you still need to do some work to let Node.js know you’re using ES modules. The two most common methods are to use.mjs file extensions, or to specify “type”:”module” in the nearest parent package.json file.

  • ** Option 1: ** will.jsRename the file to.mjsFile.
  • ** Option 2: ** Update the rootpackage.jsonFile, or putpackage.jsonAdd to the directory that contains the ES module, and placetypeSpecified asmodule.
{
   "type": "module"
}
Copy the code

Another possibility is to enable the ES module in the root package.json file and then rename all CommonJS module files to use the.cjs extension.

I personally find the.mjs and.cjs extensions sketchy, so I’d love to see some way to specify the use of ES and CommonJS modules through package.json files.

Node.js can import WebAssembly modules

In addition to ES module support, you can also import WebAssembly (Wasm) modules! This is a portable compiled binary format with the faster parsing speed of JavaScript and the ability to execute at native speed. WebAssembly modules can be created using C/C++, Go, C#, Java, Python, Elixir, Rust, etc.

As of this writing, WebAssembly module support is still experimental. To enable this feature, you need to pass the command line flag when executing the Node.js program. Such as:

node --experimental-wasm-modules index.js
Copy the code

Suppose you have an image processing library implemented as a WebAssembly module. The syntax for using this Wasm module is shown below.

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 );
} )();
Copy the code

You can also import using the new dynamic import() statement in Node.js.

"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 );
} )();
Copy the code

WebAssembly System Interface (WASI)

Like JavaScript, WebAssembly is designed with security in mind to prevent any access to the underlying operating system (sometimes referred to as “sandbox”). But sometimes WebAssembly modules in Node.js might benefit from being able to make system-level calls.

Hence the new WebAssembly System Interface (WASI). WASI is designed as a standard interface for making calls to underlying systems, such as host applications, operating systems, and so on.

Support for WASI was recently submitted for the Node.js project. WASI could be another exciting feature to see in 2020!

A diagnostic report will be released in 2020

Diagnostic reports are jSON-formatted summaries of process information that can be read by humans, including call stacks, operating system information, loaded modules, and other useful data that can help support the application. These reports can be triggered when unhandled exceptions, fatal errors, process signals, or using the new process.report API. Diagnostic reports can be configured in Node.js and saved to a folder with the specified file name.

At the time of writing, the diagnostic report is still experimental. To enable this feature, pass the command line flag when executing the Node.js program:

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

Internationalization support will be expanded in 2020

Starting with V13.x, Node.js comes with a full ICU (Unicode’s internationalization component). ICU is a mature and popular global library. This includes support for formatting numbers, dates, times, and currencies, the ability to perform time calculations and string comparisons, and the ability to convert text between Unicode and other character sets.

Other node.js updates for 2020

  • **QUIC protocol support: ** A modern transport with enhanced performance and reliability.
  • ** Better Python 3 build support: ** In 2020, it should be possible to build Node.js and native modules with Python 3.
  • Updated V8 JavaScript engine: Versions 7.8 and 7.9 of V8 have improved performance and support for Wasm.
  • Stable Worker Threads API: Worker Threads in Node.js support parallel, CPU-heavy JavaScript operations.

Learn more about Node.js, JavaScript, and security

This article is just the beginning of all the hard work of improving Node.js in 2020! If you’re interested in keeping up with the latest updates or want to get involved in some way, check out ways to contribute to Node.js on the node.js website.

Welcome to pay attention to the front public number: front pioneer, free webpack from the entry to the full series of advanced tutorials.