Skip to content

Commit 1a9ca52

Browse files
aduh95richardlau
authored andcommitted
doc: add ESM examples in module API doc page
PR-URL: #34875 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Guy Bedford <[email protected]>
1 parent 0ac7d54 commit 1a9ca52

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

doc/api/module.md

+23-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* {Object}
88

99
Provides general utility methods when interacting with instances of
10-
`Module`, the `module` variable often seen in file modules. Accessed
11-
via `require('module')`.
10+
`Module`, the [`module`][] variable often seen in [CommonJS][] modules. Accessed
11+
via `import 'module'` or `require('module')`.
1212

1313
### `module.builtinModules`
1414
<!-- YAML
@@ -27,6 +27,14 @@ if a module is maintained by a third party or not.
2727
by the [module wrapper][]. To access it, require the `Module` module:
2828

2929
```js
30+
// module.mjs
31+
// In an ECMAScript module
32+
import { builtinModules as builtin } from 'module';
33+
```
34+
35+
```js
36+
// module.cjs
37+
// In a CommonJS module
3038
const builtin = require('module').builtinModules;
3139
```
3240

@@ -74,8 +82,8 @@ added: v12.12.0
7482
-->
7583
7684
The `module.syncBuiltinESMExports()` method updates all the live bindings for
77-
builtin ES Modules to match the properties of the CommonJS exports. It does
78-
not add or remove exported names from the ES Modules.
85+
builtin [ES Modules][] to match the properties of the [CommonJS][] exports. It
86+
does not add or remove exported names from the [ES Modules][].
7987
8088
```js
8189
const fs = require('fs');
@@ -116,6 +124,14 @@ To enable source map parsing, Node.js must be run with the flag
116124
[`NODE_V8_COVERAGE=dir`][].
117125
118126
```js
127+
// module.mjs
128+
// In an ECMAScript module
129+
import { findSourceMap, SourceMap } from 'module';
130+
```
131+
132+
```js
133+
// module.cjs
134+
// In a CommonJS module
119135
const { findSourceMap, SourceMap } = require('module');
120136
```
121137
@@ -192,3 +208,6 @@ consists of the following keys:
192208
[`createRequire()`]: #module_module_createrequire_filename
193209
[module wrapper]: modules_cjs.html#modules_cjs_the_module_wrapper
194210
[source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx
211+
[`module`]: modules.html#modules_the_module_object
212+
[CommonJS]: modules.html
213+
[ES Modules]: esm.html

0 commit comments

Comments
 (0)