JavaScript platform Node.js 22.0.0 available

Node.js 22.0 was released, a platform for running network applications in JavaScript. Node.js 22.0 is classified as a long-term support branch, but this status will be assigned only in October, after stabilization. Node.js 22.x will be supported until April 30, 2027. Maintenance of the previous LTS branch of Node.js 20.x will last until April 2026, and the year before last LTS branch 18.x until April 2025. The staging branch of Node.js 21.x will be discontinued on June 1, 2024.

Main improvements:

  • The V8 engine has been updated to version 12.4, used in Chromium 124. Among the changes compared to the Node.js 21 branch, which used the V8 11.8 engine), it is noted:
    • Support for the WasmGC extension, which simplifies the porting of programs written in programming languages ​​that use a garbage collector (Kotlin, PHP, Java, etc.) to WebAssembly. WasmGC adds new types of structures and arrays that can use non-linear memory allocation.
    • Support for the Array.fromAsync() method, which asynchronously returns a new instance of an Array object copied from an array-like, iterable or async iterable object.
    • Support for iterator methods such as .map, .filter, .find, .take, .drop, .forEach and .reduce.
    • Support for a Set object that defines a collection of values ​​and offers methods that implement common set operations, such as intersection, union, difference, and addition.
  • The Maglev optimizing JIT compiler is enabled by default, aimed at quickly generating high-performance machine code for heavily used JavaScript code. Enabling Maglev can significantly speed up short-lived CLI applications that do not perform long-term operations, for example, the time to complete the Jetstrea test is reduced by 7.5%, and the Speedometer test by 5%.
  • Work with streams has been accelerated by increasing the value of the highWaterMark option from 16 KB to 65 KB (defines the limit up to which recording is buffered). The change results in increased memory consumption, so applications designed to run on limited RAM may need to revert to the old value via a call to setDefaultHighWaterMark().
  • Improved performance of the fetch() and test runner APIs by making AbortSignal instantiation more efficient. The performance of APIs related to synchronous work with file systems has been improved.
  • An experimental feature has been provided to use the "require()" call to load JavaScript ESM modules (ECMAScript Modules) in synchronous mode. ESM modules are used in browsers and replace CommonJS modules specific to Node.js. To load via "require()", the ESM module must be executed in synchronous mode (without await at the top level). Support is enabled via the “--experimental-require-module” flag.
  • Added experimental ability to run scripts defined in the package.json file using the "--run" command "
  • The “node –watch” command has been moved to the stable category with the implementation of a watch mode that ensures that the process is restarted when the imported file changes (for example, if “node –watch index.js” is executed, the process will be automatically restarted when index.js changes).
  • The native implementation of the WebSocket API has been stabilized, allowing WebSocket to be used in client mode without installing additional dependencies.
  • Added partial support for the Navigator API.
  • The Webstreams API has added support for the deflate-raw compression format.
  • Added glob and globSync functions to node:fsmodule for pattern matching of file paths.
  • Improved handling of incorrectly configured IPv6 stacks. Implemented Happy Eyeballs algorithm for quick rollback in case of problems with IPv6 operation.
  • The util API has been deprecated.
  • Updated dependency versions: npm 10.5.1, libuv 1.48.0, simdutf 5.2.3, c-ares 1.28.1, zlib 1.3.0.1-motley-24c07df, simdjson to 3.8.0, ada 2.7.7 and undici 6.6.0 .

The Node.js platform can be used both for server-side support of web applications and for creating standard client- and server-side network programs. To expand the functionality of Node.js applications, a large collection of modules has been prepared, including those implementing servers and clients of HTTP, SMTP, XMPP, DNS, FTP, IMAP, POP3, modules for integration with various web frameworks, WebSocket and Ajax handlers, connectors to DBMS (MySQL, PostgreSQL, SQLite, MongoDB), template engines, CSS engines, implementations of cryptographic algorithms and authorization systems (OAuth), XML parsers.

To handle large numbers of parallel requests, Node.js uses an asynchronous code execution model based on non-blocking event processing and defining callback handlers. Supported methods for multiplexing connections include epoll, kqueue, /dev/poll, and select. For connection multiplexing, the libuv library is used, which is an add-on to libev on Unix systems and to IOCP on Windows. The libeio library is used to create a thread pool, and c-ares is integrated to perform DNS queries in a non-blocking mode. All system calls that cause blocking are executed within the thread pool and then, like signal handlers, pass the result of their work back through an unnamed pipe.

Execution of JavaScript code is ensured through the use of the V8 engine developed by Google (in addition, Microsoft is developing a version of Node.js with the Chakra-Core engine). At its core, Node.js is similar to the Perl AnyEvent, Ruby Event Machine, Python Twisted frameworks and the implementation of events in Tcl, but the event loop in Node.js is hidden from the developer and resembles event processing in a web application running in browser.

Source: opennet.ru

Add a comment