Server-side JavaScript platform Node.js 20.0 available

The release of Node.js 20.0, a platform for executing network applications in JavaScript, has taken place. Node.js 20.0 has been assigned to the long support branch, but this status will not be assigned until October, after stabilization. Node.js 20.x will be supported until April 30, 2026. Maintenance of the previous Node.js 18.x LTS branch will last until April 2025, and the previous 16.x LTS branch until September 2023. The 14.x LTS branch will be demaintained on April 30, and the Node.js 19.x interim branch on June 1.

Main improvements:

  • The V8 engine has been updated to version 11.3, which is used in Chromium 113. Of the changes compared to the Node.js 19 branch, which used the Chromium 107 engine, the String.prototype.isWellFormed and toWellFormed functions, the Array.prototype and TypedArray.prototype methods to work with copy on change of Array and TypedArray objects, "v" flag in RegExp, support for resizing ArrayBuffer and increasing the size of SharedArrayBuffer, tail-call in WebAssembly.
  • An experimental Permission Model mechanism is proposed that allows you to restrict access to certain resources during execution. Permission Model support is enabled by specifying the "--experimental-permission" flag when running. In the initial implementation, options were proposed to restrict write (--allow-fs-write) and read (--allow-fs-read) access to certain parts of the FS, child processes (--allow-child-process), add-ons (--no-addons ) and threads (--allow-worker). For example, to allow writing to the /tmp directory and reading the /home/index.js file, you can specify: node --experimental-permission --allow-fs-write=/tmp/ --allow-fs-read=/home/index.js index .js

    To check access, it is suggested to use the process.permission.has() method, for example, "process.permission.has('fs.write',"/tmp/test").

  • Handlers for ECMAScript external modules (ESMs) loaded via the "--experimental-loader" option are now executed in a separate thread, isolated from the main thread, which eliminates the intersection of application code and loaded ESM modules. Similar to browsers, the import.meta.resolve() method now executes synchronously when called from within an application. In one of the next branches of Node.js, ESM loading support is planned to be moved to the category of stable features.
  • The node:test (test_runner) module, designed to create and run JavaScript tests that return results in TAP (Test Anything Protocol) format, has been moved to stable.
  • A separate performance team has been formed, which, in preparation for the new branch, has worked to speed up various runtime components, including URL parsing, fetch() and EventTarget. For example, the overhead of initializing the EventTarget has been halved, the performance of the URL.canParse() method has been significantly improved, and the efficiency of the timers has been improved. In addition, the release of a high-performance URL parser - Ada 2.0, written in C ++, is included in the composition.
  • The development of an experimental feature for delivering applications in the form of a single executable file (SEA, Single Executable Applications) has continued. Creating an executable now requires substituting a blob generated from a JSON configuration file (instead of substituting a JavaScript file).
  • Improved Web Crypto API compatibility with implementations from other projects.
  • Added official support for Windows on ARM64 systems.
  • Continued support for WASI (WebAssembly System Interface) extensions for creating standalone WebAssembly applications. Removed the need to specify a special command line flag to enable WASI support.

The Node.js platform can be used both for server maintenance of Web applications and for creating regular client and server network programs. To expand the functionality of applications for Node.js, a large collection of modules has been prepared, in which you can find modules with the implementation of HTTP, SMTP, XMPP, DNS, FTP, IMAP, POP3 servers and clients, modules for integration with various web frameworks, WebSocket and Ajax handlers , DBMS connectors (MySQL, PostgreSQL, SQLite, MongoDB), templating engines, CSS engines, implementations of crypto algorithms and authorization systems (OAuth), XML parsers.

To ensure the processing of a large number of parallel requests, Node.js uses an asynchronous code execution model based on non-blocking event handling and the definition of callback handlers. Supported methods for multiplexing connections are epoll, kqueue, /dev/poll, and select. For connection multiplexing, the libuv library is used, which is an add-on for libev on Unix systems and IOCP on Windows. The libeio library is used to create a thread pool, and c-ares is integrated to perform DNS queries in non-blocking mode. All system calls that cause blocking are executed inside the thread pool and then, like signal handlers, transfer the result of their work back through an unnamed pipe (pipe). The execution of JavaScript code is provided 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 Tcl event implementation, but the event loop in Node.js is hidden from the developer and resembles event handling in a web application running in browser. When writing applications for node.js, you need to consider the specifics of event-driven programming, for example, instead of doing "var result = db.query("select..");" with waiting for completion of work and subsequent processing of results, Node.js uses the principle of asynchronous execution, i.e. the code is transformed into "db.query("select..", function (result) {result processing});", in which control will instantly pass to further code, and the query result will be processed as data arrives.

Source: opennet.ru

Add a comment