Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the new features of Node18

Shulou Source: shulou.com Published: 2022-05-31 20:18:06 09月21日 Update

This article introduces the relevant knowledge of "what are the new features of Node18". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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

Experimental fetch API is supported in the global environment of Node. The implementation is based on undici, a HTTP/1.1 client written for Node.

Meanwhile, Node can now use the following global variables: fetch, FormData, Headers, Request, and Response.

two。 Built-in test runnerimport test from 'node:test'; import * as assert from' assert/strict'; test ('sync test', (t) = > {assert.equal (1,1);}); test (' async test', async (t) = > {assert.equal (1,1);}); 3. Web Streams

Node downloads support Web Streams API (MDN), which means that Node allows JavaScript to programmatically access data streams received over the network through Streams API.

4. Blob

Buffer's new Blob API,Blob encapsulates immutable raw data, which can be safely shared among multiple worker threads.

In addition, the new BroadcastChannel instance allows asynchronous one-to-many communication with all other BroadcastChannel instances bound to the same channel name.

5. Use the new version of V8

V8 will be updated to version 10.1, which is part of Chromium 101s. Compared to Node.JS 17.9.0, it includes the following new features:

FindLast () and findlastedex () array methods.

Improvements to Intl.Locale API.

Intl.SupportedValues of the function.

Improved performance of class fields and private class methods (they are now initialized as fast as normal property stores).

6. Support for import JSON

The Import Assertions proposal adds inline syntax to the module import statement. The purpose of such assertions is to support other types of modules in a common way across JavaScript environments, starting with JSON modules.

The syntax is as follows (recommended methods for importing JSON modules):

Import json from ". / foo.json" assert {type: "json"}; import ("foo.json", {assert: {type: "json"}); and that's all for "what are the new features of Node18". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Support module data method property global content instance way more environment knowledge grammar primitive achievement and then between functions variables you can make Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MySQL NVidia Shulou Tech Info Redmi