Skip to content

Commit e06c587

Browse files
musgravejwtargos
authored andcommitted
doc: add global node_modules to require.resolve()
PR-URL: #20534 Fixes: #18926 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 1d7379d commit e06c587

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

doc/api/modules.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ LOAD_AS_DIRECTORY(X)
175175
2. LOAD_INDEX(X)
176176
177177
LOAD_NODE_MODULES(X, START)
178-
1. let DIRS=NODE_MODULES_PATHS(START)
178+
1. let DIRS = NODE_MODULES_PATHS(START)
179179
2. for each DIR in DIRS:
180180
a. LOAD_AS_FILE(DIR/X)
181181
b. LOAD_AS_DIRECTORY(DIR/X)
182182
183183
NODE_MODULES_PATHS(START)
184184
1. let PARTS = path split(START)
185185
2. let I = count of PARTS - 1
186-
3. let DIRS = []
186+
3. let DIRS = [GLOBAL_FOLDERS]
187187
4. while I >= 0,
188188
a. if PARTS[I] = "node_modules" CONTINUE
189189
b. DIR = path join(PARTS[0 .. I] + "node_modules")
@@ -419,7 +419,7 @@ when people are unaware that `NODE_PATH` must be set. Sometimes a
419419
module's dependencies change, causing a different version (or even a
420420
different module) to be loaded as the `NODE_PATH` is searched.
421421

422-
Additionally, Node.js will search in the following locations:
422+
Additionally, Node.js will search in the following list of GLOBAL_FOLDERS:
423423

424424
* 1: `$HOME/.node_modules`
425425
* 2: `$HOME/.node_libraries`
@@ -649,9 +649,11 @@ changes:
649649
* `request` {string} The module path to resolve.
650650
* `options` {Object}
651651
* `paths` {string[]} Paths to resolve module location from. If present, these
652-
paths are used instead of the default resolution paths. Note that each of
653-
these paths is used as a starting point for the module resolution algorithm,
654-
meaning that the `node_modules` hierarchy is checked from this location.
652+
paths are used instead of the default resolution paths, with the exception
653+
of [GLOBAL_FOLDERS][] like `$HOME/.node_modules`, which are always
654+
included. Note that each of these paths is used as a starting point for
655+
the module resolution algorithm, meaning that the `node_modules` hierarchy
656+
is checked from this location.
655657
* Returns: {string}
656658

657659
Use the internal `require()` machinery to look up the location of a module,
@@ -891,6 +893,7 @@ const builtin = require('module').builtinModules;
891893
[`Error`]: errors.html#errors_class_error
892894
[`module` object]: #modules_the_module_object
893895
[`path.dirname()`]: path.html#path_path_dirname_path
896+
[GLOBAL_FOLDERS]: #modules_loading_from_the_global_folders
894897
[exports shortcut]: #modules_exports_shortcut
895898
[module resolution]: #modules_all_together
896899
[module wrapper]: #modules_the_module_wrapper

0 commit comments

Comments
 (0)