Node.js 21 released with stable fetch API, Node.js 20 becomes long-term support release

Node.js 21 released with stable fetch API, Node.js 20 becomes long-term support release

The Node.js team has released version 21, which also means that Node 20 will shortly become the active Long Term Support (LTS) release. New features include stable fetch and WebStreams, a flag for defaulting .js files to ECMAScript modules (esm) rather than CommonJS, and an updated test runner.

A stable fetch API in Node is a big deal. The fetch API is used intensively in modern web applications for asynchronous data requests, using JavaScript promises, but its appearance in Node.js has been delayed because it depends on web stream support, an API for handling streaming data. Rival runtimes Deno and the new Bun already support fetch. Developers have been able to use fetch in Node since version 18, or via a module, but this is the first time fetch in Node core has been declared stable.

There is also experimental support for a WebSocket client in Node.js, though not yet a server, however, both are already available via modules. “A webSocket server … may follow”, according to TSC member Benjamin Gruenbaum.

Node.js 21 also edges closer towards using ESM rather than CommonJS for its default module system. Currently files with a .cjs or .js extension are treated as CommonJS, but a new experimental flag changes this so that .js files are treated as ESM.

The V8 JavaScript engine in Node.js 21 is updated to 11.8 in this release.

Node.js releases appear every six months, and even-numbered releases become LTS. Odd-numbered releases like 21 will never be LTS, but they do herald the promotion of the previous current release to active so are still significant. The purpose of the odd-numbered releases is to give developers “access to interesting new features early … a great way to test and see what’s coming,” according to Rafael Gonzaga, Node.js Technical Steering Committee member.

Developers may be equally interested in features introduced in Node.js 19 and 20 that are now becoming current. A key feature in Node.js 20 is a stable Test Runner built into the core, with building blocks for authoring and running tests, and a watch mode to check for file changes – though note that not all the features of the Test Runner are stable, with code coverage and reporting still being experimental.

Node.js 20 also has a focus on performance with “many improvements to the fundamental parts of the runtime” according to the release notes. There is also experimental support for single executable applications , which means applications can be distributed without requiring Node.js to be installed, though in the initial release it supports CommonJS modules only.