Node.js recently introduced a node: protocol for built-in modules. Built-in node modules can now be imported by prefixing the node: protocol prefix.
So, what previously used to be
- Advertisement -
import * as fs from 'fs/promises';
can now be imported as
import * as fs from 'node:fs/promises';
Benefits
- More explicit protocol makes it more readable and also makes it clear that a built-in module is being imported. Since there are a lot of built-in ones, this extra information is useful for beginners or for someone who might not know about one of them.
- It reduces the risk of a module present in node_modules overriding the newer imports.
It is currently supported:
- In Node.js starting:
- v16.0.0, v14.18.0 (ESMÂ
import
 and CommonJSÂrequire()
) - v14.13.1, v12.20.0 (only ESMÂ
import
)
- v16.0.0, v14.18.0 (ESMÂ
- In TypeScript by the latest versions ofÂ
@types/node
.