Node.js 21 brings WebSocket client
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.
A new flag, –experimental-default-type, can flip the default module system used by Node.js. Input explicitly defined as ES modules or ComThe 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.
monJS, 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 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.