This blog post is part of the series What’s new in Node.js core?
It can be hard to tell from just looking at code whether a module that’s being imported is a built in Node.js module, or a third-party dependency. Who can remember the names of all the core modules? Certainly not me!
You can use the
node: protocol to make it clear in your code when you’re importing built in Node.js modules. It makes it much easier then to see the modules which are being imported from third-party dependencies.
/** * Using the `node:` protocol in an ES module. * * Added: v14.13.1 * Backported to: 12.x (v12.20.0) */ import url from "node:url"; /** * Using the `node:` protocol in a CommonJS module. * * Added: v16.0.0 * Backported to: None */ const url = require("node:url");