Node.js 22 Features and Updates

    Friday, May 3, 20248 min read347 views
    Node.js 22 Features and Updates

    Last week, Node unveiled Node.js 22 available for developers. The major highlights include requiring ES modules, a WebSocket client, updates of the V8 JavaScript engine, and so much more. The Node.js 22 is a future release and will enter long-term support in October of this year and till then this can be considered as a 'current' release.

    Node.js is an open-source, cross-platform runtime that grants developers to create server-side applications and tools with JavaScript. The Node.js 22 is an in-progress project and therefore the modifications mentioned in the Changelog only showcase a small portion of features and updates till the future release.

    Node.js 22 alters Node.js 21 as the current release line. Developers and the Node community are encouraged to explore the new features and advantages brought by the current release. This will analyze and evaluate the significant impact of Node.js 22 on your application.

    Let's explore the notable changes brought by the current release.

    Notable Changes

    Rafael Gonzaga, Node.js Technical Steering Committee (TSC) Member expressed, "Node.js 22 improves a lot of small, important areas, and continues to make it easy in enterprise deployments to use JavaScript to write command line tools and for server-side scripting."

    He also added, "The broad Node.js community is critical to the continued improvement of the software and a big part of this release. Many thanks to our open-source contributors for putting in the time and effort and making Node.js better with each release. Thank you also to OpenSSF and Project Alpha Omega for helping us improve Node.js security.”

    There are at least 8 potential updates in Node.js 22 and let us find out what updates will make developers' life easier and coding simple.

    V8 JavaScript Engine Updated

    V8 JavaScript engine is from Google, also a WebAssembly engine, and is updated to 12.4. It is written with CSS and is now used in Node.js 22. The new features of the version include WebAssembly Garbage Collection and Array.fromAsync, Set methods, and iterator helpers.

    Maglev

    The V8 JavaScript engine also includes Maglev a new compiler. It was initially introduced in December 2023. Maglev is enabled by default in some of the supported architectures too. The aim here is to produce a greatly optimized code and for the supported architectures, it should provide a performance boost. This in turn will also optimize CPU usage and enhance the overall performance of the application.

    Employ Performance, Scalability, and Rich Ecosystem with Node.JS
    Angular Minds is a promising
    Nodejs development company for creating web and mobile applications for your next project.

    Supported ESM Graphs

    Another major update is the require()ing ESM graphs. The ECMAScript Modules is a new JavaScript module system in comparison to the CommonJS module. The release includes require() support for synchronous ESM graphs in the code --experimental-require-module.

    For developers, if --experimental-require-module is employed and the ECMAScript module is loaded by require() and you fulfill two conditions:

    • Completely marked as an ES module with a "type": "module" field in the closest package.json or a .mjs extension

    • Fully synchronous

    As a result, require() will show the requested module as an ES Module, and return the module namespace object. In instances like the above, it is akin to dynamic import() but is run synchronously and returns the namespace object directly. The intention here is to eventually enable require(esm) by default in the future, without the flag.

    Running package.json scripts

    A new experimental feature is also added in the release. This came into the picture for the execution of scripts from the package.json with the cli flag node --run <script-in-package-json>. This will also support node --run test which performs the test command inside package.json scripts.

    Stream Default High Water Mark

    Node.js has elevated the default High Water Mark for streams from 16KiB to 64KiB. This will give a performance boost through the board at a slightly higher memory usage. Developers or users who are in a memory sensitive environments are recommended to set: setDefaultHighWaterMark

    Watch Mode (node --watch)

    With Node.js 22, the watch mode is now evaluated and considered stable. A factor to keep in mind is when developers are in watch mode, changes made in the watch mode file will cause the node.js process to restart.

    WebSocket

    Earlier under the colors --experimental-websocket, now the browser-compatible implementation of WebSocket will be employed by default. This will achieve WebSocket client to Node.js without potential external dependencies.

    glob and globSync

    An addition to this release is toward the node: fs module the functions glob and globSync for pattern matching. Developers can make use of these functions for matching file paths based on particular patterns.

    Improve Performance of AbortSignal Creation

    The efficiency to create AbortSignal instances is enhanced and optimized in this version. This will lead to a substantial performance improvement in fetch and test runner.

    Final Thoughts

    The features in the Node.js 22 look promising and the developer continues to test it to see the future compatibility of their project on the current version. The optimum version will be officially released in October 2024. So developers have to wait for a little more time to see the stable version.

    The features and updates brought in this version aim to boost performance and make things easier for users. It is Rafael Gonzaga's recommendation to jump to Node.js 20 and prepare to hop on to Node.js 22 as soon as possible.

    Read More: 6 Ways to Make Your Node JS Web App Faster

    24

    Related articles

    This website uses cookies to analyze website traffic and optimize your website experience. By continuing, you agree to our use of cookies as described in our Privacy Policy.