The release of Node.js 18.0 has taken place, a platform for running network applications in JavaScript. Node.js 18.0 is classified as a long-term support (LTS) branch, but this status will be assigned only in October after stabilization is completed. Support for Node.js 18.x will continue until April 2025. Support for the previous LTS branch, Node.js 16.x, will last until April 2024, and for the branch before that, 14.x, until April 2023. Support for LTS branch 12.x will end on April 30, and for the interim branch Node.js 17.x on June 1.
Key Improvements:
- The V8 engine has been updated to version 10.1, used in Chromium 101. Compared to the release of Node.js 17.9.0, support has been added for features such as the findLast and findLastIndex methods for searching elements relative to the end of an array and the Intl.supportedValuesOf function. The API Intl.Locale has been improved. Initialization of class fields and private methods has been accelerated.
- The experimental fetch() API has been enabled by default, designed for loading resources over the network. The implementation is based on code from the HTTP/1.1 client undici and is closely aligned with the similar API provided in browsers. This includes support for the FormData, Headers, Request, and Response interfaces for manipulating HTTP request and response headers. const res = await fetch(‘https://nodejs.org/api/documentation.json’); if (res.ok) { const data = await res.json(); console.log(data); }
- An experimental implementation of the Web Streams API has been added, providing access to data streams obtained over the network. The API allows you to add your own handlers to process data as it arrives over the network, without waiting for the entire file to load. Node.js now supports objects such as ReadableStream*, TransformStream*, WritableStream*, TextEncoderStream, TextDecoderStream, CompressionStream, and DecompressionStream.
- The Blob API has been promoted to stable status, which allows encapsulating immutable raw data for safe use across different worker threads.
- The BroadcastChannel API has been promoted to stable status, enabling asynchronous message exchange in a "one sender — many receivers" format.
- An experimental module node:test has been added for creating and running tests in JavaScript, returning results in TAP (Test Anything Protocol) format.
- Ready-to-use builds for Red Hat Enterprise Linux (RHEL) 8 and other distributions based on Glibc 2.28+, including Debian 10 and Ubuntu 20.04, as well as for macOS 10.15+, are now available. Due to issues with building the V8 engine, the creation of 32-bit builds for Windows has been temporarily halted.
- An experimental feature has been provided to build the Node.js executable with user-selected components initialized at startup. To determine the starting components, the configure script has been updated with the option '—node-snapshot-main', for example, './configure —node-snapshot-main=marked.js; name node'.
The Node.js platform can be used for both server-side support of web applications and for creating standard client and server network applications. A large collection of modules has been prepared to extend the functionality of Node.js applications, where modules with implementations can be found. servers and clients for HTTP, SMTP, XMPP, DNS, FTP, IMAP, POP3, modules for integration with various web frameworks, WebSocket and Ajax handlers, connectors to databases (MySQL, PostgreSQL, SQLite, MongoDB), templating engines, CSS engines, implementations of cryptographic algorithms and authorization systems (OAuth), XML parsers.
To handle a large number of parallel requests, Node.js utilizes an asynchronous code execution model based on event-driven non-blocking I/O and the definition of callback handlers. Multiplexing methods such as epoll, kqueue, /dev/poll, and select are supported for connection multiplexing. The libuv library is used for connection multiplexing, which is a wrapper around libev on Unix systems and IOCP on Windows. The libeio library is employed to create a thread pool, while c-ares is integrated for non-blocking DNS requests. All blocking system calls are executed within the thread pool, and like signal handlers, they pass their results back through an unnamed pipe. JavaScript code execution is ensured through the use of the V8 engine developed by Google (additionally, Microsoft develops a version of Node.js with the Chakra-Core engine).
Essentially, Node.js is similar to the Perl AnyEvent, Ruby Event Machine, Python Twisted frameworks, and the event handling implementation in Tcl, but the event loop in Node.js is abstracted away from the developer and resembles the event processing in a web application running in a browser. When developing applications for Node.js, it is crucial to consider the specifics of event-driven programming. For example, instead of executing "var result = db.query('select...');" and waiting for its completion before processing the results, Node.js employs asynchronous execution, meaning the code is transformed into "db.query('select...', function (result) {process result});" allowing control to pass immediately to the subsequent code, with the query results processed as data arrives.
Source: opennet.ru
