Announced October 17, Node.js 21 is equipped with an experimental, browser-compatible WebSocket implementation, enabled through the
--experimental-websocket flag. WebSocket enables two-way communication between a browser and server, with no need to poll the server for a reply.
Node.js 21 also features an upgraded test runner, which adds support for glob expressions when specifying the
--test parameter. This means developers now can use powerful glob patterns to run tests more efficiently.
Downloadable from nodejs.org, Node.js 21 will replace Node.js 20 as the Current release line when Node.js 20 becomes the LTS (Long Term Support) release later this month. Node.js 21 is slated to be the Current release until April 2024.
Other improvements in Node.js 21:
- A new flag,
--experimental-default-type, can flip the default module system used by Node.js. Input explicitly defined as ES modules or CommonJS, such as by the package.json “type” field or the .mjs/cjs file extension, are unaffected. With the flag, what currently is implicitly CommonJS instead will be interpreted as ES modules under
--experimental-default-type=module. Extensionless files are interpreted as WebAssembly if
--experimental-wasm-modulesis passed and the file begins with the WebAssembly preamble,