Skip to content

Commit 98ce82a

Browse files
Renegade334aduh95
authored andcommitted
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 f173cc9 commit 98ce82a

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:
@@ -220,7 +224,7 @@ resolution and loading behavior. See [Customization hooks][].
220224
221225
This feature requires `--allow-worker` if used with the [Permission Model][].
222226
223-
### `module.registerHooks(options)`
227+
## `module.registerHooks(options)`
224228
225229
<!-- YAML
226230
added:
@@ -249,7 +253,7 @@ Register [hooks][] that customize Node.js module resolution and loading behavior
249253
See [Customization hooks][]. The returned object can be used to
250254
[deregister the hooks][deregistration of synchronous customization hooks].
251255
252-
### `module.stripTypeScriptTypes(code[, options])`
256+
## `module.stripTypeScriptTypes(code[, options])`
253257
254258
<!-- YAML
255259
added:
@@ -314,7 +318,7 @@ console.log(strippedCode);
314318
// Prints: const a = 1\n\n//# sourceURL=source.ts;
315319
```
316320
317-
### `module.syncBuiltinESMExports()`
321+
## `module.syncBuiltinESMExports()`
318322
319323
<!-- YAML
320324
added: v12.12.0
@@ -2073,9 +2077,9 @@ returned object contains the following keys:
20732077
[`module.enableCompileCache()`]: #moduleenablecompilecacheoptions
20742078
[`module.flushCompileCache()`]: #moduleflushcompilecache
20752079
[`module.getCompileCacheDir()`]: #modulegetcompilecachedir
2080+
[`module.isBuiltin()`]: #moduleisbuiltinmodulename
20762081
[`module.registerHooks()`]: #moduleregisterhooksoptions
20772082
[`module.setSourceMapsSupport()`]: #modulesetsourcemapssupportenabled-options
2078-
[`module`]: #the-module-object
20792083
[`os.tmpdir()`]: os.md#ostmpdir
20802084
[`register`]: #moduleregisterspecifier-parenturl-options
20812085
[`util.TextDecoder`]: util.md#class-utiltextdecoder
@@ -2088,11 +2092,11 @@ returned object contains the following keys:
20882092
[hooks]: #customization-hooks
20892093
[load hook]: #synchronous-loadurl-context-nextload
20902094
[module compile cache]: #module-compile-cache
2091-
[module wrapper]: modules.md#the-module-wrapper
20922095
[realm]: https://tc39.es/ecma262/#realm
20932096
[resolve hook]: #synchronous-resolvespecifier-context-nextresolve
20942097
[source map include directives]: https://tc39.es/ecma426/#sec-linking-generated-code
20952098
[synchronous hook functions]: #hook-functions-accepted-by-moduleregisterhooks
2099+
[the `module` object]: modules.md#the-module-object
20962100
[the documentation of `Worker`]: worker_threads.md#new-workerfilename-options
20972101
[transferable objects]: worker_threads.md#portpostmessagevalue-transferlist
20982102
[type-stripping]: typescript.md#type-stripping

0 commit comments

Comments
 (0)