The server-side JavaScript platform Node.js 21.0 is now available.

The release of Node.js 21.0 has occurred, which is a platform for running network applications in JavaScript. Support for Node.js 21.0 will be maintained for 6 months. Stabilization of Node.js 20 will be completed in the coming days, which will receive LTS status and be supported until April 2026. The previous LTS branch Node.js 18.0 will be supported until September 2025, and the earlier LTS branch 16.0 until April 2024.

Key Improvements:

  • The stable Fetch API has been announced, designed for loading resources over the network and simplifying the writing of universal JavaScript code usable on both the server and client sides. The implementation is based on the code from the HTTP/1.1 client undici and closely resembles the similar API offered in browsers. The API includes the fetch() method and the Headers, Request, and Response objects representing HTTP headers, requests, and responses. const res = await fetch('https://nodejs.org/api/documentation.json'); if (res.ok) { const data = await res.json(); console.log(data); }
  • Support for the WebStreams API has been stabilized, providing access to data streams received over the network. The API allows you to add your own handlers that work with the data as it is received, without waiting for the entire file to load. In Node.js, such objects as ReadableStream*, TransformStream*, WritableStream*, TextEncoderStream, TextDecoderStream, CompressionStream, and DecompressionStream are available.
  • An experimental implementation of a WebSocket client has been added, compatible with browsers.. To enable WebSocket support, the ‘--experimental-websocket’ flag is provided.
  • An experimental mode has been added for default usage of the JavaScript module implementation ESM (ECMAScript Modules, used in browser modules) instead of CommonJS (specific to Node.js). This change does not affect modules whose format is explicitly defined through the 'type' field in package.json, set via the ‘--input-type’ flag, or is evident due to the file extension (.mjs for ESM, .cjs for CommonJS). Modules that are not explicitly defined as CommonJS (for example, those with a '.js' extension) will be treated as ESM modules with the new mode enabled. A flag ‘--experimental-default-type’ is suggested to activate the new module settings.
  • The V8 engine has been updated to version 11.8, which is used in Chromium 118, introducing support for the ArrayBuffer.prototype.transfer method, capabilities for grouping arrays (the groupBy method), and WebAssembly instructions for handling constants (i32.add, i32.sub, i32.mul, i64.add, i64.sub, and i64.mul).
  • Support for the globalPreload handler has been discontinued; instead, module configuration should utilize the register and initialize calls.
  • The fs.writeFile function has been enhanced with a 'flush' option to force data to be flushed to the storage device after each write operation.
  • Performance has been improved for code related to parsing URLs, the fetch API, streams, node:fs, and HTTP.
  • A global navigator object has been added. For instance, to get data about the number of CPU cores, one can use the navigator.hardwareConcurrency property.
  • Support for glob patterns has been added to the '--test' parameter for selecting tests to run (for example, you can specify '--test **/*.test.js').
  • The included package manager npm has been updated to version 10.2.0, and the llhttp parser has been updated to version 9.1.2.
  • Support for Visual Studio 2019 and macOS versions older than 11.0 has been discontinued.

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

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster