Summary of NodeJs latest version features

(The best way to predict the future is to invent it - Negroponte)

insert image description here

NodeJs

Official link
github link
V8 link
Node.js was released in May 2009, developed by Ryan Dahl, is a JavaScript runtime environment based on the Chrome V8 engine, using an event-driven, non-blocking I/O model, [1] Let JavaScript runs on the server-side development platform, which makes JavaScript a scripting language on par with server-side languages ​​such as PHP, Python, Perl, and Ruby. [2]
Node.js optimizes some special use cases and provides alternative APIs to make V8 run better in non-browser environments. The V8 engine executes Javascript very fast and has very good performance. It is based on the Chrome JavaScript runtime. A platform for conveniently building fast-responsive and easy-to-extend network applications

The following are the commonly used features in development. Some authors think that the features that are not commonly used may not be recorded or recorded in detail.

NodeJs publishing rules

  • CURRENT: Refers to the latest Node.js release series.
  • Active: Refers to a release series that is being actively maintained and upgraded, including backporting non-breaking features and improvements, resolving bugs, and patching security holes.
  • Maintenance: This is a maintenance LTS release series until its end of life, receiving bug fixes and security patches only for a short period of time.
  • LTS: It is the abbreviation of Long-Term Support, which represents the long-term supported version of Node.js (the version number is plural).
  • EOL: EOL is the acronym for End of Life, and the version that enters the EOL timeline will not be maintained.

Let's see what the lifecycle of a Node.js version looks like? First of all, you need to know that even-numbered and odd-numbered versions are released in April and October each year. The following is a description of the process:

The most recent even-numbered release lasts 6 months after the April release. An odd-numbered version will be released in October, and the nearest even-numbered version will enter the Active LTS version. The duration is 18 months. During this period, there will be almost no incompatible major function updates, and developers can also upgrade to the Active LTS version with confidence.
After the 18-month Active LTS version expires, it will enter the Maintenance LTS version, that is, enter the maintenance period for 12
months, during which only security and bug updates will be performed. Once the 12-month period of the Maintenance LTS version is up, it will enter the EOL
version and officially exit the stage of history.
Among them, the even-numbered version will continue to be maintained for 18 months, while the odd-numbered version will be maintained for 8 months.
life cycle diagram
insert image description here

20.0.0

Released on 2023-04-18

1. Permission model

Node.js now has an experimental feature called the permission model. It allows developers to restrict access to specific resources during program execution, such as file system operations, child process spawning, and worker thread creation. The API exists behind a flag --experimental-permission, which when enabled will restrict access to all available permissions. By using this feature, developers can prevent their applications from accessing or modifying sensitive data or running potentially harmful code.

  • Use --allow-fs-read and --allow-fs-write to restrict access to the file read and write system
  • Use --allow-child-process to restrict access to child_process
  • Use --allow-worker to restrict access to worker_threads
  • Use --no-addons to restrict access to native addons

2. Custom ESM loader hooks run on dedicated threads

ESM hooks provided via loader() --experimental-loader=foo.mjs now run in a dedicated thread isolated from the main thread. This provides a separate scope for the loader and ensures that there is no cross-contamination between the loader and application code.

3. import.meta.resolve()

For consistency with browser behavior, this function now returns synchronously. Nevertheless, user loaded resolver hooks can still be defined as asynchronous functions (or synchronous functions, if the author prefers). Even if resolve is loaded with async hooks, import.meta.resolve will still return to application code synchronously.

4. V8 11.3

The V8 engine was updated to version 11.3, which is part of Chromium 113. This release includes three new features of the JavaScript API

  • String.prototype.isWellFormed and toWellFormed
    isWellFormed is used to check whether the string is a legal Unicode, and toWellFormed will convert a string to Unicode.
Methods for mutating Array and TypedArray by copying
The existing Array.prototype and TypedArray.prototype functions will directly modify the received array. Instead, the new function returns a modified copy of the received array, leaving the original array unchanged. These new functions are useful in programming styles where data is immutable.
Resizable ArrayBuffer and Growable SharedArrayBuffer
Properties of RegExp v flags + strings with set notation
WebAssembly tail calls

5. Stable test runner

A recent update to Node.js version 20 includes important changes to the test_runner module. After a recent update, this module has been marked as stable. Previously, the test_runner module was experimental, but this change marks it as a stable module ready for production.
It is mainly used to write and run test files, similar to mock and other test component packages

  • describe/it/test functions, and hooks for test files.
  • mock data.
  • Monitor file change mode (watch mode).
  • node --test supports running multiple test files in parallel.
import {
    
     test, mock } from "node:test";
import assert from "node:assert";
import fs from "node:fs";

mock.method(fs, "readFile", async () => "Hello ZY");
test("synchronous passing test", async (t) => {
    
    
  // This test passes because it does not throw an exception.
  assert.strictEqual(await fs.readFile("zy.txt"), "Hello ZY");
});

6. Ada 2.0

Node.js v20 ships with the latest version of the URL parser Ada. This update brings significant performance improvements to URL parsing, including enhancements to url.domainToASCII.url.domainToUnicodenode:url

Ada 2.0 has been integrated into the Node.js codebase, ensuring that all parts of the application benefit from improved performance. Additionally, Ada 2.0 offers significant performance improvements over its predecessor, Ada 1.0.4, while also eliminating the ICU requirement for URL hostname resolution.

19.0.0

Released on 2022-10-18

1. HTTP(S)/1.1 KeepAlive default

Starting with this release, Node.jskeepAlive is set to true by default. This means that any outgoing HTTP(s) connections will automatically use HTTP 1.1 Keep-Alive. The default wait time is 5 seconds. Enabling keep-alive will provide better throughput because connections are reused by default.

Additionally, the proxy is now able to parse responses that may be sent by Keep-Alive servers. This header indicates how well the client is keeping the connection alive. On the other hand, the Node.js HTTP server will now automatically disconnect idle clients (use HTTP Keep-Alive to reuse connections) when calling close().

Node.js HTTP(S)/1.1 requests may experience better throughput/performance by default.

2. Removed DTrace/SystemTap/ETW support

3. V8 10.7

The V8 engine was updated to version 10.7, which is part of Chromium 107. This release includes a new function to the JavaScript API: Intl.NumberFormat.

The Intl.NumberFormatv3 API is a new TC39 ECMA402 Phase 3 proposal that extends the existing Intl.NumberFormat.

4. llhttp 8.1.0

llhttp has been updated to version 8.1.0. Overall, this release brings many updates to the llhttp API, introducing new callbacks and allowing all callbacks to be paused.

18.0.0

Released on 2022-04-19

1. fetch (experimental)

An experimental fetch API is provided globally by default. The implementation is based on undici, an HTTP/1.1 client for Node.js written by project contributors.

const res = await fetch('https://nodejs.org/api/documentation.json');
if (res.ok) {
    
    
  const data = await res.json();
  console.log(data);
}

With this addition, the following global variables are available: fetch, FormData, Headers, Request, Response
Use the --no-experimental-fetch command line flag to disable this API

2. HTTP timeout

server.headersTimeout This limits how long the parser waits to receive full HTTP headers, it is now set to 60000 by default (60 seconds).

server.requestTimeout300000 sets the timeout value in milliseconds for receiving an entire request from a client. It is now set to (5 minutes) by default.

If these timeouts expire, the server will respond with status 408 without forwarding the request to the request listener, and then close the connection.

Both timeouts must be set to a non-zero value to prevent potential denial of service attacks without a reverse proxy in front of the server deployment.

3. Test Runner module (experimental)

The node:test module helps create JavaScript tests that report results in TAP format.

import test from 'node:test';

This module is only available under the scheme node:
Here is an example implementation of a parent test with two child tests:

test('top level test', async (t) => {
    
    
  await t.test('subtest 1', (t) => {
    
    
    assert.strictEqual(1, 1);
  });

  await t.test('subtest 2', (t) => {
    
    
    assert.strictEqual(2, 2);
  });
});

4. Tool chain and compiler upgrade

5. V8 10.1

The V8 engine was updated to version 10.1, which is part of Chromium 101. Compared to the version included in Node.js 17.9.0, including the following new features

findLast array findLastIndex method
const inputArray = [{
    
    v:1}, {
    
    v:2}, {
    
    v:3}, {
    
    v:4}, {
    
    v:5}];
inputArray.findLast((element) => element.v % 2 === 0);
// → {v:4}
inputArray.findLast((element) => element.v % 7 === 0);
// → undefined
inputArray.findLastIndex((element) => element.v % 2 === 0);
// → 3
inputArray.findLastIndex((element) => element.v % 7 === 0);
// → -1
Improvements to the Intl.Locale API.
Intl.supportedValuesOf
Improved performance of class fields and private class methods (their initialization is now as fast as normal property storage)

17.0.0

2021-10-19 release

1. OpenSSL 3.0

2. V8 9.5

V8 JavaScript engine updated to V8 9.5. This release comes with additional supported types from Intl.DisplayNamesAPI and extended options from timeZoneNameAPI Intl.DateTimeFormat

3. Readline Promise API

This module provides an interface for reading data from a Readable stream (such as readline ) one line at a time. process.stdin

The following simple example illustrates the basic usage of the readline module

import * as readline from 'node:readline/promises';
import {
    
     stdin as input, stdout as output } from 'process';

const rl = readline.createInterface({
    
     input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${
      
      answer}`);

rl.close();

16.0.0

Posted on 2021-04-21

1. Stabilize the Timers Promises API

The Timers Promises API provides a set of alternative timer functions that return Promise objects. Added in Node.js v15.0.0, in which they were promoted from experimental to stable state.

import {
    
     setTimeout } from 'timers/promises';

async function run() {
    
    
  const res = await setTimeout(3000, 'fullFilledValue');
  console.log(`Get result=>${
      
      res} after 3s`);
}

run(); // 3s后输出:Get result=>fullFilledValue after 3s

2. Tool chain and compiler upgrade

3. V8 JavaScript engine updated to V8 9.0, including performance adjustments and improvements

This V8 upgrade brings the ECMAScript RegExp comparison index function, which can provide the start and end indexes of strings. When the regular expression has the /d tag, the index array can be accessed through the indices property.

14.0.0

Released on 2020-04-21

1. V8 8.1

optional link
Nullish merge
Intl.DisplayNames
Enable calendar and numberingSystem options for Intl.DateTimeFormat

2. Experimental asynchronous local storage API

3. Enhanced streaming API

13.0.0

Released on 2019-10-22

1. Affirmations

If a validation function passed to assert.throws() or assert.rejects() returns a value other than true, an assertion error will be thrown instead of the original error to highlight programming errors (Ruben Bridgewater)

2. build

The Node.js version is now built with default full-icu support. This means that all locales supported by ICU are now included, and international-related APIs may return different values ​​than before (Richard Lau)

3. V8 7.8

Added performance improvements for object destructuring, memory usage, and WebAssembly startup time

12.0.0

Released on 2019-04-29

1. V8 7.4

In V8 7.4, the most important new feature for developers is estimated computed properties, which allows developers to more easily define object properties through expressions, and introduces more prototype methods. In addition, V8 7.4 also implements a large number of memory management and performance improvements, which will make the performance of Node.js 12 more stable and reliable.

2. Faster ES module loading

As web applications become larger and larger, the speed of loading and parsing JavaScript modules becomes more and more the bottleneck of web development. To address this, Node.js 12 introduces the newer V8 version's Fast Object Store Access, which makes ES modules load and parse faster, enabling faster web application load times and startup times.

3. Full support for HTTP/2

As the next generation of HTTP protocol, HTTP/2 has faster and safer data transmission speed than HTTP 1.x. Node.js 12 supports complete support for HTTP/2, including complete flow control for HTTP/2 streams, decoding of procedural binary protocols, and support for H2C upgrades. Similarly, Node.js 12 also supports the ALPN protocol, using HTTP/2 in HTTPS requests.

11.0.0

Released on 2018-10-23

1. V8 7.0

2. fs

  1. The fs.read() method now requires a callback
  2. The previously deprecated fs.SyncWriteStream utility has been removed

3. console

  1. console.countReset() will warn if the reset timer does not exist
  2. console.time() will no longer reset the timer if it already exists

10.0.0

Released on 2018-04-24

1. Affirmations

  1. Added assert.rejects() and assert.doesNotReject() methods to use async functions
  2. assert.throws() accepts an object to compare errors against

2. Asynchronous hooks

  1. The old experimental async_hooks API has been removed

3. Buffer

  1. Using the directory new Buffer() and Buffer() outside the directory node_modules will now issue a runtime deprecation warning
  2. Buffer.isEncoding() now returns undefined bogus values, including empty strings
  3. Buffer.fill() if trying to fill an empty Buffer
  4. The noAssert parameter has been removed from all Buffer read and write functions

4. V8 6.6

5. Send event

The EventEmitter.prototype.off() method has been added as an alias for EventEmitter.prototype.removeListener()

6. fs

  1. APIfs/promises provides an experimental promise version of the function fs
  2. now throws an invalid path error synchronously
  3. The fs.readFile() method now partitions reads to avoid thread pool exhaustion

7. Subsequent versions of node10x open worker threads

Worker threads are mainly used to solve business problems of node computing. But it should be noted that it has no effect on io type operations.

Guess you like

Origin blog.csdn.net/qq_42427109/article/details/130581875