We use cookies and similar technologies that are necessary to operate the website. Additional cookies are used to perform analysis of website usage. please read our Privacy Policy

Node.js 22 Release Notes: Explore New Features and Updates

Web July 2, 2024
img

Check out how the new version of Node.js 22 has made a huge improvement for JavaScript runtime environments. Learn how it helps developers create stronger, faster, and more efficient applications. In this blog, we cover all the new features and updates from the Node.js team. Keep reading for useful information!

Node.js 22 is here, bringing exciting new features and updates. Released in April 2024, it is now the “Current” version globally, giving developers a better web app development experience.

The “Current” version is expected to become the “Long-Term Support (LTS)” version in October 2024. The release announcement recommends the community to switch from Node.js 18 to Node.js 20 (LTS) or Node.js 22 (soon to be LTS) because Node.js 18 will become obsolete in April 2025.

Let’s learn about the latest version of Node.js! It includes new features and fixes, like a WebSocket client, the ability to use require() with ES modules, and updates to the V8 JavaScript engine. Let’s see what Node.js v22 offers and how we can use it to improve our application development.

What’s new in Node.js 22 version?

Node.js has released Node.js 22, replacing version 21. It came out on April 24, 2024. This new version includes many exciting features and improvements, like the Maglev compiler, new add-on APIs, and updates for running package.json scripts. These changes aim to help developers create more scalable applications.

With more people wanting reliable and scalable apps, Node.js is becoming very popular among developers. The new Node.js version 22 aims to improve and provide features that make it easier for over 242,797 companies worldwide (as of 2024) to develop their backend systems smoothly.

What are The Latest Features and New Updates in Node.js 22?

Node.js 22 has some great new features like cool ways to work with arrays, new helper functions for iterators, and updated methods for sets. Take a look at what version 22 has to offer. Installing this latest version can improve your app’s performance and make users happier.

1. V8 Upgraded to 12.4

Node.js 22, with its 12.4 release, has made the V8 engine better. It includes new features like set methods, Array.fromAsync, Web Assembly Garbage Collection, and iterator helpers, giving developers powerful tools to boost application performance.

2. Maglev Compiler

Node.js 22, with its 12.4 release, has made the V8 engine better. It includes new features like set methods, Array.fromAsync, Web Assembly Garbage Collection, and iterator helpers, giving developers powerful tools to boost application performance.

3. ESM Compatibility Enhancement

Version 22 has improved compatibility with ECMAScript Modules (ESM) by adding features like import.meta.filename and import.meta.dirname, which were first introduced in Node.js 21. It also makes it easier to switch from CommonJS (CJS) to ESM with a new experimental flag called experimental-detect-module. This flag helps developers automatically run ES modules when their syntax is detected.

4. Deprecations in util

The latest release gives developers a good way to manage outdated APIs. It introduces a structured process with three stages: documentation-only, runtime, and end-of-life.

Notably, several utility APIs have been phased out during the runtime in Node.js 22. Developers should check for deprecated APIs by running their apps with the –throw-deprecation flag. This helps ensure a smoother transition.

When moving to Node.js 22, it’s also helpful to review and replace deprecated APIs to make your apps work better and be more compatible.

5. Web Socket

If you use Web Sockets in Node.js 22, there’s a big improvement. Before, you had to enable browser-compatible features with a special flag -experimental-websocket. Now, these features work automatically without needing extra settings, which reduces the need for external tools.

6. Add-on APIs and Better Defining of Environment Variables

In this new release, you receive several new tools that improve essential functions and reduce the need for extra components. These tools include a test runner, WebSocket, and argument parser. Additionally, there’s a Text Styling API that makes it easier to format text using util.inspect.colors, giving you more options for how text looks.

Version 22 brings significant improvements for setting file environment variables. You can now easily use the –env-file command-line option to enable this functionality. Additionally, commands like process.loadEnvFile and util.parseEnv make it simpler to manage .env files, enhancing the overall development experience by reducing friction.

7. glob and glogSync

The fs module now includes new features alongside the glob and globSync functions for matching file patterns. These updates make it easier for Node.js product development teams to find and work with specific file paths in Node.js applications, improving how they manage and manipulate file systems.

8. Support require () ESM Graphs

Node.js 22 now includes support for require() in ECMAScript modules (ESM) under the flag -experimental-require-module. When this flag is turned on, Node.js can use require() with ECMAScript modules, which are the standard for scripting languages like JavaScript, under below conditions:

  • It’s marked as an ES module by having either a 'type: "module"' field in the closest package.json file or by using a .mjs extension.
  • It happens all at the same time.

In this case, require() treats the requested module as an ES Module and returns the module’s namespace object. It works like import() but does so synchronously, immediately giving you access to the namespace object.

9. Running package.json scripts

Node.js version 22 introduces a new feature that lets you run scripts directly from your package.json file using a command line interface (CLI) flag called node -run <script-in-package-json>. This feature includes a command node-run test specifically designed to execute the test command defined in your package.json scripts.

10. Stream Default High Water Mark

In Node.js Version 22, they’ve increased the standard amount of data streams can handle at once, from 16KiB to 64KiB. This change should make streams work faster, although it uses a bit more memory. If developers work in a memory-sensitive setup, they might need to adjust something called -setDefaultHighWaterMark.

11. Stable Watch Mode Command Line

The latest update has made the Watch Mode Command Line option more stable. It also includes additional options, like –

  • watch
  • watch-path
  • watch-preserve-output

This new feature helps developers make web app development process more effective by automatically restarting them whenever they change the watched files during development.

12. AbortSignal Creation Performance Improvement

In the latest Node.js version, running AbortSignal instances has been improved. This will greatly boost how well fetch and test runner functions work.

Conclsuion

Try out the new Node.js 22 release! We’re always happy to hear your feedback. Testing your applications and modules with Node.js 22 helps to ensure the future compatibility of your project with the latest Node.js changes and features. Looking to hire Node.js developers or need Node.js development services? Contact us today!

 

We are here

Our team is always eager to know what you are looking for. Drop them a Hi!

    100% confidential and secure

    Prashant Suthar

    Meet Prashant Suthar, a Sr. Software Developer at Zealous System. With a passion for building elegant code and solving complex problems, Prashant transforms ideas into digital solutions that drive business success.

    Comments

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Table Of Contents