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.
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.
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.