Skip to content

Commit 10720f7

Browse files
authored
doc: replace node:modules documentation header
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #65800 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 8af7545 commit 10720f7

1 file changed

Lines changed: 34 additions & 30 deletions

File tree

‎doc/api/module.md‎

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@
22

33
<!--introduced_in=v12.20.0-->
44

5+
> Stability: 2 - Stable
6+
7+
<!-- source_link=lib/module.js -->
8+
9+
The `node:module` module provides utilities for interacting with the Node.js
10+
module system.
11+
12+
It can be accessed using:
13+
14+
```mjs
15+
import module from 'node:module';
16+
```
17+
18+
## Class: `Module`
19+
520
<!-- YAML
6-
added: v0.3.7
21+
added: v0.3.5
722
-->
823

9-
## The `Module` object
24+
`module` objects in [CommonJS][] modules are instances of this class.
1025

11-
* Type: {Object}
26+
See the CommonJS documentation for [the `module` object][].
1227

13-
Provides general utility methods when interacting with instances of
14-
`Module`, the [`module`][] variable often seen in [CommonJS][] modules. Accessed
15-
via `import 'node:module'` or `require('node:module')`.
16-
17-
### `module.builtinModules`
28+
## `module.builtinModules`
1829

1930
<!-- YAML
2031
added:
@@ -29,25 +40,18 @@ changes:
2940

3041
* Type: {string\[]}
3142

32-
A list of the names of all modules provided by Node.js. Can be used to verify
33-
if a module is maintained by a third party or not.
34-
35-
`module` in this context isn't the same object that's provided
36-
by the [module wrapper][]. To access it, require the `Module` module:
43+
A list of the names of all modules provided by Node.js.
3744

3845
```mjs
39-
// module.mjs
40-
// In an ECMAScript module
41-
import { builtinModules as builtin } from 'node:module';
46+
import { builtinModules } from 'node:module';
47+
console.log(builtinModules.filter((name) => name.startsWith('path')));
48+
// Prints: [ 'path', 'path/posix', 'path/win32' ]
4249
```
4350

44-
```cjs
45-
// module.cjs
46-
// In a CommonJS module
47-
const builtin = require('node:module').builtinModules;
48-
```
51+
To test whether a module name corresponds to a builtin module, use
52+
[`module.isBuiltin()`][].
4953

50-
### `module.createRequire(filename)`
54+
## `module.createRequire(filename)`
5155

5256
<!-- YAML
5357
added: v12.2.0
@@ -66,7 +70,7 @@ const require = createRequire(import.meta.url);
6670
const siblingModule = require('./sibling-module');
6771
```
6872
69-
### `module.findPackageJSON(specifier[, base])`
73+
## `module.findPackageJSON(specifier[, base])`
7074
7175
<!-- YAML
7276
added:
@@ -154,7 +158,7 @@ findPackageJSON('@foo/qux', __filename);
154158
// '/path/to/project/packages/qux/package.json'
155159
```
156160
157-
### `module.isBuiltin(moduleName)`
161+
## `module.isBuiltin(moduleName)`
158162
159163
<!-- YAML
160164
added:
@@ -172,7 +176,7 @@ isBuiltin('fs'); // true
172176
isBuiltin('wss'); // false
173177
```
174178
175-
### `module.register(specifier[, parentURL][, options])`
179+
## `module.register(specifier[, parentURL][, options])`
176180
177181
<!-- YAML
178182
added:
@@ -222,7 +226,7 @@ resolution and loading behavior. See [Customization hooks][].
222226
223227
This feature requires `--allow-worker` if used with the [Permission Model][].
224228
225-
### `module.registerHooks(options)`
229+
## `module.registerHooks(options)`
226230
227231
<!-- YAML
228232
added:
@@ -251,7 +255,7 @@ Register [hooks][] that customize Node.js module resolution and loading behavior
251255
See [Customization hooks][]. The returned object can be used to
252256
[deregister the hooks][deregistration of synchronous customization hooks].
253257
254-
### `module.stripTypeScriptTypes(code[, options])`
258+
## `module.stripTypeScriptTypes(code[, options])`
255259
256260
<!-- YAML
257261
added:
@@ -316,7 +320,7 @@ console.log(strippedCode);
316320
// Prints: const a = 1\n\n//# sourceURL=source.ts;
317321
```
318322
319-
### `module.syncBuiltinESMExports()`
323+
## `module.syncBuiltinESMExports()`
320324
321325
<!-- YAML
322326
added: v12.12.0
@@ -2094,9 +2098,9 @@ returned object contains the following keys:
20942098
[`module.enableCompileCache()`]: #moduleenablecompilecacheoptions
20952099
[`module.flushCompileCache()`]: #moduleflushcompilecache
20962100
[`module.getCompileCacheDir()`]: #modulegetcompilecachedir
2101+
[`module.isBuiltin()`]: #moduleisbuiltinmodulename
20972102
[`module.registerHooks()`]: #moduleregisterhooksoptions
20982103
[`module.setSourceMapsSupport()`]: #modulesetsourcemapssupportenabled-options
2099-
[`module`]: #the-module-object
21002104
[`os.tmpdir()`]: os.md#ostmpdir
21012105
[`register`]: #moduleregisterspecifier-parenturl-options
21022106
[`util.TextDecoder`]: util.md#class-utiltextdecoder
@@ -2109,11 +2113,11 @@ returned object contains the following keys:
21092113
[hooks]: #customization-hooks
21102114
[load hook]: #synchronous-loadurl-context-nextload
21112115
[module compile cache]: #module-compile-cache
2112-
[module wrapper]: modules.md#the-module-wrapper
21132116
[realm]: https://tc39.es/ecma262/#realm
21142117
[resolve hook]: #synchronous-resolvespecifier-context-nextresolve
21152118
[source map include directives]: https://tc39.es/ecma426/#sec-linking-generated-code
21162119
[synchronous hook functions]: #hook-functions-accepted-by-moduleregisterhooks
2120+
[the `module` object]: modules.md#the-module-object
21172121
[the documentation of `Worker`]: worker_threads.md#new-workerfilename-options
21182122
[transferable objects]: worker_threads.md#portpostmessagevalue-transferlist
21192123
[type-stripping]: typescript.md#type-stripping

0 commit comments

Comments
 (0)