X Tutup
The Wayback Machine - https://web.archive.org/web/20210422091234/https://github.com/nodejs/node/issues/38343
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the node: protocol in docs examples #38343

Open
sindresorhus opened this issue Apr 22, 2021 · 1 comment
Open

Use the node: protocol in docs examples #38343

sindresorhus opened this issue Apr 22, 2021 · 1 comment
Labels

Comments

@sindresorhus
Copy link

@sindresorhus sindresorhus commented Apr 22, 2021

The node: protocol has many benefits:

  • Makes it perfectly clear that the import is a Node.js builtin module. (Beginners don't always realize this)
  • Makes the import identifier a valid absolute URL.
  • Avoids conflicts for future Node.js builtin modules.

However, most people don't know about the node: protocol. I suggest Node.js makes it the recommended way of importing builtin modules by using it in all the examples in the documentation. A lot of people are starting to move to ESM, so now would be a good time for people to switch to the node: protocol too.

Personally, I plan to switch all my packages to use the node: protocol. We have also made an ESLint rule for it.

@aduh95
Copy link
Contributor

@aduh95 aduh95 commented Apr 22, 2021

We may want to wait for this support for node: on require() calls to be backported to v14.x before changing all the docs, but I'm all for it personally.

We have also made an ESLint rule for it.

That's really nice, thanks for doing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
X Tutup