Node.js · Junior · Question 18 of 75
What is the recommended way to import a built-in module?
- 1With a relative path, e.g.
./fs - 2From the
@node/fspackage - ✓Correct answer: With the
node:prefix, e.g.import fs from "node:fs"
Explanation
The node: prefix makes it clear the module is built in and cannot be shadowed by a package with the same name in node_modules. Some newer modules, such as node:test, work only with it.