Node.js 21 brings WebSocket client

Latest release of popular JavaScript runtime also features test runner improvements and enhanced V8 engine.

shutterstock 610036778 casino table with cards showing blackjack hand 21 jack and ace
StockStudio Aerials

Node.js 21, the latest release of the open source cross-platform JavaScript runtime, has arrived, featuring a built-in WebSocket client and support for globs in the platform’s test runner.

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-modules is passed and the file begins with the WebAssembly preamble, \0asm.
  • The Node.js development team is exploring the use of detection of ES module syntax as a way for Node.js to know when to interpret files as ES modules. The goal is to eventually find a way to support ES module syntax by default with minimal breaking changes.
  • The fetch and WebStreams implementations are now stable.
  • A global navigator object has been introduced to enhance web interoperability. Developers can access hardware concurrency information through navigator.hardwareConcurrency.
  • The Google V8 JavaScript/WebAssembly engine has been upgraded to version 11.8, offering better performance and language features such as array grouping and WebAssembly extended-const expressions.
  • Streams have been optimized by removing redundant checks, utilizing bitmaps, and scheduling callbacks more efficiently.

Node.js 21 was preceded by Node.js 20.8.1 and Node.js 20.8.0, both of which were announced within the past three weeks.

Copyright © 2023 IDG Communications, Inc.