Updated

Published

Node 22

Node.js v22 has come out with new stable features

Node.js' logo

Node.js version 22 has been released on April 24th, 2024. This release brings some improvements, new features, and newly stable features

Table of contents

Use require() with ESM dependencies

As a new experimental feature, you can now use the --experimental-require-module flag to have Node.js load ESM dependencies using require(). However, there are two important considerations for this to work, according to the Node.js docs:

  • “Explicitly marked as an ES module with a "type": "module" field in the closest package.json or a .mjs extension.”
  • “Fully synchronous (contains no top-level await).”

If your ESM dependencies meet those expectations, you can now use them with CommonJS modules in Node.js 22.

Task Runner

As an alternative to npm run or yarn run, Node.js v22 now has a built-in task runner to run the “scripts” in a package.json file. By using the new --run flag, you can run any script. For example node --run generate will run the “generate” script.

Check out my full tutorial on the Node.js Task Runner.

Now stable

Both --watch and the browser-compatible WebSockets are now considered stable.

To use the WebSocket implementation you no longer need the --experimental-websocket as it will be enabled by default.

How to get Node.js v22

To get any of these new features and improvements, download Node.js version 22 from nodejs.org.

You can also use a Node.js version manager like Volta.

Further Reading

Related Posts