Node.js 22 is Out: Overview of Key Innovations
On April 22, 2024, the official release of Node.js 22 took place — a new stable version of the popular server-side JavaScript platform. This update brings many improvements in performance, security, and developer experience. Let's break down the most interesting parts.
Main Changes in Node.js 22
1. V8 Engine Updated to Version 12.4
Node.js 22 is powered by the new V8 12.4 engine, which is already used in Chrome 124. Key improvements include:
- Array optimization — the new
Array.fromAsyncallows creating arrays from async iterators without extra promises. - Faster parsing — thanks to an improved JIT compiler, code execution speed has increased by an average of 5–10%.
- New methods for RegExp — support for the
vflag has been added for more flexible regular expression syntax.
2. WebSocket Becomes Stable (No Flag Required)
Previously, WebSocket in Node.js was experimental and required running with the --experimental-websocket flag. In version 22, it has finally achieved stable API status. Now you can use the built-in WebSocket without additional configuration:
const ws = new WebSocket('ws://example.com');ws.onmessage = (event) => console.log(event.data);This simplifies building real-time applications — chats, trackers, games.
3. ESM Modules by Default for Scripts
Starting with Node.js 22, if you run a script with the .mjs extension or have "type": "module" specified in package.json, the CommonJS module system is no longer used by default. This is an important step towards standardizing the ecosystem around ES modules.
- Simplified imports — now
import/exportworks natively without transpilers. - Top-level await support — you can await promises at the top level of a module.
4. Improved Streams
New methods for working with streams have been added:
ReadableStream.from()— allows creating readable streams from any iterators (e.g., from Set or Map).WritableStream.getWriter()— simplifies writing data to streams without extra wrappers.
5. Enhanced Security
In Node.js 22, security policies have been strengthened:
- Automatic escaping when outputting data to the console via
console.log()to prevent injections. - Deprecated crypto algorithms disabled by default (e.g., SHA-1 for signatures).
What Does This Mean for Developers?
Node.js 22 is not just another release, but an important milestone in the platform's evolution. The main benefits for developers:
- Fewer dependencies — built-in WebSocket and stable ESM allow you to drop third-party packages (e.g.,
wsoresm). - Higher performance — thanks to optimizations