Last updated: March 31, 2022
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 with `import`. * * Added: v14.13.1 * Backported: v12.20.0 */ import url from "node:url"; /** * Using the `node:` protocol with `require()`. * * Added: v16.0.0 * Backported: v14.18.0 */ const url = require("node:url");
Support in Node.js
- Added: v14.13.1 (import), v16.0.0 (require)
- Backported: v12.20.0 (import), v14.18.0 (require)
When v12 goes End-of-life on 30th April 2022, all Current and LTS release lines (v14, v16, v18) will have support for the
node: protocol when using
- Documentation: Node.js import, Node.js require()
- Node.js release notes: v12.20.0, v14.13.1, v14.18.0, v16.0.0
- Twitter thread: Posted on Jul 23, 2021