×
iFour Logo

What’s new in Node.js 18: A comprehensive guide

iFour Team - September 20, 2022

Listening is fun too.

Straighten your back and cherish with coffee - PLAY !

What’s new in Node.js 18: A comprehensive guide

Node.js 18 has arrived! What does it bring to the table for Node.js development companies and their developers?

Applications built using Node.js are extremely quick and scalable. But what makes it so quick? Obviously, its support for asynchronous and single threaded IO model. Node.js releases a new version every six months, bringing new features to the LTS (Long Term Support) channel. The most recent version of Node.js have been phenomenal as it brought remarkable and improved capabilities to the board. It included updates to the V8 engine to 10.1, a core test runner module, and global fetch enabled by default.

It will be supported for 6 months before being switched to LTS, where it will be referred with a codename as the "Hydrogen".

Node 18 is now available! What changes does it bring?

Node.js 18 was released on April 19, 2022, with incredible feature support. Before we get into the details, here is an overview of the features we will be discussing in this blog.

  • Browser-compatible APIs can be accessed globally
  • Fetch and Built-in Test Runner Module
  • Web Streams API
  • Build Time user-land Snapshot
  • Compiler and Toolchain Upgrades
  • V8 10.1
  • Other updates of Node.js

Looking to hire Node.js developers ? Your search ends here.

Browser-compatible APIs can be accessed globally

Previously, experts had to rely on third-party packages (such as Axios) and the http.request API, which needed a large amount of code to call and get data. Also, the Fetch API was experimental at this point and will remain tentative until further test coverage is added. Moreover, the aspects that previously needed a browser were now removed in this version.

An example of this API is as follows:


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

Using this, the following globals are made available: Request, fetch,  FormData, Headers and Response. You can disable the API by using the command --no-experimental-fetch.

Test Runner Module

Node professionals may now develop project tests without having to rely on third-party packages or libraries. This is one of the most important enhancements included in this edition.

It allows experts to write JavaScript tests and present the results in TAP format. When a disc image is generated from a data storage tape prepared for ZX spectrum systems or C64 computers, it is referred to as TAP format. To go there, type:

Import test from ‘Node:test’;

Here is an example of it:


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


The test runner module is only available when using the node: prefix. Note that the node: prefix indicates the loading of a core module. If the prefix is left out, importing ‘test’ would attempt to load a userland module.

Web Streams API

Node.js has now unveiled the experimental implementation of the Web Stream APIs. This statement basically means that the following APIs are available globally:

ReadableStream, ReadableStreamDefaultReader, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, TransformStream, DecompressionStream, CompressionStream TransformStreamDefaultController, WritableStream, WritableStreamDefaultController, ByteLengthQueuingStrategy, CountQueuingStrategy, TextEncoderStream, ReadableByteStreamController, WritableStreamDefaultWriter, ReadableStreamDefaultController TextDecoderStream.

Web-stream-API-Nodejs

The above diagram helps you understand how web stream APIs are employed in Node.js.

Build Time user-land Snapshot

Node.js 18 may now allow users to build a Node.js binary with a custom V8 start-up snapshot using the --node-snapshot-main flag of the configure script. Here is a brief look:


$ cd /path/to/node/source
$ ./configure --node-snapshot-main=marked.js

# Build the binary
$ make node


The resultant binary can deserialize the state of the heap which was initialized by the snapshot entry point during the build. Thus, the application in generated binary can be initialized quicker using the following steps:


// render.js
// snapshot so there is will be no need to parse & execute the
// module again, which improves the start-up time.
const HTML = globalThis.marked(process.argv[1]);
console.log(HTML);


We can execute the generated binary like this:


$ out/Release/node render.js test.md

To improve this, the Node.js team is working on JavaScript APIs to minimize additional runtime and make it into a single-file executable program. They are also attempting to build snapshots that can be generated and loaded without the use of a compiler.

Compiler and Toolchain Upgrades

Node.js brings forth pre-built binaries for several different platforms. For every major release, the minimum toolchains are assessed and updated cautiously.

  • The pre-built libraries are built on Red Hat Enterprise Linux (RHEL) 8 and are compatible with Linux distributions that are based upon glibc 2.28 or later, for example, Ubuntu 20.04, Debian 10, RHEL 8, etc.
  • The minimum architectural support for AIX has been upgraded from Power 7 to Power 8.
  • MacOS 10.15 or later is essential for prebuilt binaries of Mac Operating System.

Earlier, the prebuilt binaries were not accessible on Windows 32-bit due to difficulties encountered while generating V8 dependencies. Several experts assumed that the team would restore 32-bit Windows binaries in this new release. However, Node has discontinued support for Operating Systems that are no longer supported by their respective suppliers.

Seeking for a reliable custom software development company ? Contact us now.

V8 10.1

An interesting aspect of this new version is the V8 engine update. It was updated to version 10.1 which is being a part of Chromium 101. Compared to the version included in Node.js 17.9.0, the following features are included:

  • Improvements to the Intl.Locale API

  • The findLastIndex() and  findLast() array methods.

  • The Intl.supportedValuesOf() function.

  • Improved performance of class fields and private class methods (Their initialization is now as fast as ordinary property stores).

Miscellaneous updates of Node.js

The Node community is constantly working on ECMAScript modules, loaders and their enhancements. As part of their goal-oriented milestone, they are also striving to introduce experimental support for JSON Import Assertions, unflagging of JSON modules and experimental support for HTTPS and HTTP import as well.

The team is also working on the 'Next 10,' which relates to Node's reflection on the previous ten years and Node's future vision for the upcoming ten years.

Conclusion

Node.js has been the preferred option for many major firms like Netflix, IBM, LinkedIn, Walmart, Paypal, GoDaddy, and many more, due to its ultrafast capabilities and perfect features. Node.js community always strives to improve user experience. Given this, they've made several intriguing modifications that will help developers build more efficient apps. In this blog, we have gone through the extensive updates introduced in the latest release i.e., Node.js 18.

What’s new in Node.js 18: A comprehensive guide Table of Content 1.Node 18 is now available! What changes does it bring? 2Browser-compatible APIs can be accessed globally 3Test Runner Module 4Web Streams API 5Build Time user-land Snapshot 6Compiler and Toolchain Upgrades 7V8 10.1 8Miscellaneous updates of Node.js 9Conclusion Node.js 18 has arrived! What does it bring to the table for Node.js development companies and their developers? Applications built using Node.js are extremely quick and scalable. But what makes it so quick? Obviously, its support for asynchronous and single threaded IO model. Node.js releases a new version every six months, bringing new features to the LTS (Long Term Support) channel. The most recent version of Node.js have been phenomenal as it brought remarkable and improved capabilities to the board. It included updates to the V8 engine to 10.1, a core test runner module, and global fetch enabled by default. It will be supported for 6 months before being switched to LTS, where it will be referred with a codename as the "Hydrogen". Node 18 is now available! What changes does it bring? Node.js 18 was released on April 19, 2022, with incredible feature support. Before we get into the details, here is an overview of the features we will be discussing in this blog. Browser-compatible APIs can be accessed globally Fetch and Built-in Test Runner Module Web Streams API Build Time user-land Snapshot Compiler and Toolchain Upgrades V8 10.1 Other updates of Node.js
Looking to hire Node.js developers ? Your search ends here. See here Browser-compatible APIs can be accessed globally Previously, experts had to rely on third-party packages (such as Axios) and the http.request API, which needed a large amount of code to call and get data. Also, the Fetch API was experimental at this point and will remain tentative until further test coverage is added. Moreover, the aspects that previously needed a browser were now removed in this version.

An example of this API is as follows: const response = await fetch('https://nodejs.org/api/documentation.json'); if (response.ok) { const data = await response.json(); console.log(data); } Using this, the following globals are made available: Request, fetch,  FormData, Headers and Response. You can disable the API by using the command --no-experimental-fetch. Test Runner Module Node professionals may now develop project tests without having to rely on third-party packages or libraries. This is one of the most important enhancements included in this edition. It allows experts to write JavaScript tests and present the results in TAP format. When a disc image is generated from a data storage tape prepared for ZX spectrum systems or C64 computers, it is referred to as TAP format. To go there, type: Import test from ‘Node:test’;

Here is an example of it: test('top level test', async (d) => { await d.test('subtest 1', () => { assert.strictEqual(1, 1); }); await d.test('subtest 2', () => { assert.strictEqual(2, 2); }); }); The test runner module is only available when using the node: prefix. Note that the node: prefix indicates the loading of a core module. If the prefix is left out, importing ‘test’ would attempt to load a userland module. Web Streams API Node.js has now unveiled the experimental implementation of the Web Stream APIs. This statement basically means that the following APIs are available globally: ReadableStream, ReadableStreamDefaultReader, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, TransformStream, DecompressionStream, CompressionStream TransformStreamDefaultController, WritableStream, WritableStreamDefaultController, ByteLengthQueuingStrategy, CountQueuingStrategy, TextEncoderStream, ReadableByteStreamController, WritableStreamDefaultWriter, ReadableStreamDefaultController TextDecoderStream. The above diagram helps you understand how web stream APIs are employed in Node.js.

Read More: Node.js vs Django: which one is better for backend development in 2022 Build Time user-land Snapshot

Node.js 18 may now allow users to build a Node.js binary with a custom V8 start-up snapshot using the --node-snapshot-main flag of the configure script. Here is a brief look: $ cd /path/to/node/source $ ./configure --node-snapshot-main=marked.js # Build the binary $ make node The resultant binary can deserialize the state of the heap which was initialized by the snapshot entry point during the build. Thus, the application in generated binary can be initialized quicker using the following steps: // render.js // snapshot so there is will be no need to parse & execute the // module again, which improves the start-up time. const HTML = globalThis.marked(process.argv[1]); console.log(HTML);

We can execute the generated binary like this: $ out/Release/node render.js test.md To improve this, the Node.js team is working on JavaScript APIs to minimize additional runtime and make it into a single-file executable program. They are also attempting to build snapshots that can be generated and loaded without the use of a compiler. Compiler and Toolchain Upgrades Node.js brings forth pre-built binaries for several different platforms. For every major release, the minimum toolchains are assessed and updated cautiously. The pre-built libraries are built on Red Hat Enterprise Linux (RHEL) 8 and are compatible with Linux distributions that are based upon glibc 2.28 or later, for example, Ubuntu 20.04, Debian 10, RHEL 8, etc. The minimum architectural support for AIX has been upgraded from Power 7 to Power 8. MacOS 10.15 or later is essential for prebuilt binaries of Mac Operating System. Earlier, the prebuilt binaries were not accessible on Windows 32-bit due to difficulties encountered while generating V8 dependencies. Several experts assumed that the team would restore 32-bit Windows binaries in this new release. However, Node has discontinued support for Operating Systems that are no longer supported by their respective suppliers.

Seeking for a reliable custom software development company ? Contact us now. See here V8 10.1

An interesting aspect of this new version is the V8 engine update. It was updated to version 10.1 which is being a part of Chromium 101. Compared to the version included in Node.js 17.9.0, the following features are included: Improvements to the Intl.Locale API The findLastIndex() and  findLast() array methods. The Intl.supportedValuesOf() function. Improved performance of class fields and private class methods (Their initialization is now as fast as ordinary property stores). Miscellaneous updates of Node.js The Node community is constantly working on ECMAScript modules, loaders and their enhancements. As part of their goal-oriented milestone, they are also striving to introduce experimental support for JSON Import Assertions, unflagging of JSON modules and experimental support for HTTPS and HTTP import as well. The team is also working on the 'Next 10,' which relates to Node's reflection on the previous ten years and Node's future vision for the upcoming ten years. Conclusion Node.js has been the preferred option for many major firms like Netflix, IBM, LinkedIn, Walmart, Paypal, GoDaddy, and many more, due to its ultrafast capabilities and perfect features. Node.js community always strives to improve user experience. Given this, they've made several intriguing modifications that will help developers build more efficient apps. In this blog, we have gone through the extensive updates introduced in the latest release i.e., Node.js 18.

Categories

Ensure your sustainable growth with our team

Talk to our experts
Sustainable
Sustainable
 

Blog Our insights

What’s new in Node.js 18: A comprehensive guide
What’s new in Node.js 18: A comprehensive guide

Table of Content 1.Node 18 is now available! What changes does it bring? 2Browser-compatible APIs can be accessed globally 3Test Runner Module 4Web Streams API 5Build...

Read More
Node.js vs Django: which one is better for backend development in 2022
Node.js vs Django: which one is better for backend development in 2022

Table of Content 1.Django 2.Node.js 3.Differences between Django and Node.js 4.Limitations of Node.js and Django 5.What to choose: Node.js or Django? 6.Conclusion To...

Read More
Benefits of using NoSQL with Node in 2022
Benefits of using NoSQL with Node in 2022

Table of Content 1.What exactly is Node.js? 2.What exactly is NoSQL? 3.What are the advantages of combining Node.js and NoSQL? 4.What Node.js NoSQL applications are available? 5.Conclusion Node.js...

Read More