From 2ff9c163a8ce3979232657f9b8e79c8fc031c385 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 16 Apr 2022 01:30:35 +0200 Subject: [PATCH 1/2] doc: clarify core modules that can be loaded without a prefix Refs: https://github.com/nodejs/node/pull/42325 --- doc/api/modules.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 0264c4ff558fe1..3bd839f05b78df 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -333,15 +333,17 @@ described in greater detail elsewhere in this documentation. The core modules are defined within the Node.js source and are located in the `lib/` folder. -Core modules are always preferentially loaded if their identifier is -passed to `require()`. For instance, `require('http')` will always -return the built in HTTP module, even if there is a file by that name. - -Core modules can also be identified using the `node:` prefix, in which case +Core modules can be identified using the `node:` prefix, in which case it bypasses the `require` cache. For instance, `require('node:http')` will always return the built in HTTP module, even if there is `require.cache` entry by that name. +Some core modules are always preferentially loaded if their identifier is +passed to `require()`. For instance, `require('http')` will always +return the built in HTTP module, even if there is a file by that name. The list +of core modules that can be loaded without using the `node:` prefix is exposed +as [`module.builtinModules`][]. + ## Cycles @@ -1092,6 +1094,7 @@ This section was moved to [`__dirname`]: #__dirname [`__filename`]: #__filename [`import()`]: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports +[`module.builtinModules`]: module.md#modulebuiltinmodules [`module.children`]: #modulechildren [`module.id`]: #moduleid [`module` core module]: module.md From 79261a5ba49a71c2aa9f629ad7c44acdcadcb219 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 16 Apr 2022 14:48:29 +0200 Subject: [PATCH 2/2] Update doc/api/modules.md Co-authored-by: Mohammed Keyvanzadeh --- doc/api/modules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 3bd839f05b78df..66764d5905c165 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -340,7 +340,7 @@ by that name. Some core modules are always preferentially loaded if their identifier is passed to `require()`. For instance, `require('http')` will always -return the built in HTTP module, even if there is a file by that name. The list +return the built-in HTTP module, even if there is a file by that name. The list of core modules that can be loaded without using the `node:` prefix is exposed as [`module.builtinModules`][].