The latest version of Node.js (link) , which was just released in April 2022, is brimming with helpful new features! Every developer will find these new features to be quite useful because they help improve productivity while also increasing performance. This post will discuss some of the important new features that you should start using if you are already operating an application on Node.js or if you want to begin building one from scratch.
and findLastIndex() vector methods, the Intl.supportedValuesOf function, enhancements to the Intl.Locale API, and improved performance of class fields
and private class methods were brought into existence.
Node.js Roadmap (link)
Testing is of utmost significance in our systems, and it's the best way for us to manage the risk of errors occurring in production. Typically, in order to write tests in Node.js, we make use of very common libraries such as AVA, Jest, MochaJS, and so on. However, starting with version 18, Node.js now has a native way to implement tests (link). The following is an explanation of how to use this new API:
Standalone Test Runner
It's also possible to create subtests (link) by making use of the context provided by the test() function, such as this one:
When importing this particular test module, you need to keep in mind that it begins with the node: prefix. If you don't import it in this manner, Node.js will try to locate the test package as an external package within node_modules directory.
Fetch Experimental Support
You are able to make a request and obtain the result by using the code that is shown above. Alternatively, you can implement it by using the async/await mode, as shown below:
In the above examples, we saw the most typical way of doing it, but this method only works in browsers. This means that it cannot be used in other contexts, such as on the server side, where we also want to make requests or connect to other services via fetch.However, as of version 18, they are currently working on experimental support in order to make the fetch operation possible (link). Let's look at an example:
Now, much like in browsers, we will have the ability to send requests by using the fetch method!
V8 Engine Version 10.1
Version 10.1 of the V8 engine (link) is supported in Node.js18, which brings with it a number of new features, including the following:
- The Intl.supportedValuesOf function is what we're interested in.
- Arrays now have the findLast and findLastIndex methods available to use.
- Additional enhancements made to the Intl.Locale API.
We have taken a comprehensive look at the Node.js 18 version, its breaking changes, and the reasons why you should consider upgrading any existing projects to the most recent version. The latest update to the V8 engine were also a focus of our attention.