What is the node: prefix for core module imports, and why was it introduced?
Short answer
The node: prefix explicitly signals a built-in core module rather than a third-party package -- introduced partly to remove ambiguity in module resolution and support scenarios where explicitly distinguishing core modules from userland packages matters; older unprefixed requires…
Advertisement
AModel answer
The node: prefix explicitly signals a built-in core module rather than a third-party package -- introduced partly to remove ambiguity in module resolution and support scenarios where explicitly distinguishing core modules from userland packages matters; older unprefixed requires still work for compatibility.
const fs = require('node:fs');
const fs2 = require('fs'); // still works, older styleReal-world example
A team adopts the node: prefix so a linter rule can flag accidental shadowing of a core module name by a local file, making core-module imports visually unambiguous.
Likely follow-ups
- Is the node: prefix required or merely a stylistic convention currently?
- Are there core modules that specifically require the node: prefix?
Related topics