Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
doc: add ESM examples in module API doc page
PR-URL: #34875
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
  • Loading branch information
aduh95 authored and MylesBorins committed Nov 16, 2020
1 parent f0b06b6 commit 7dc3b74
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions doc/api/module.md
Expand Up @@ -7,8 +7,8 @@
* {Object}

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

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

```js
// module.mjs
// In an ECMAScript module
import { builtinModules as builtin } from 'module';
```

```js
// module.cjs
// In a CommonJS module
const builtin = require('module').builtinModules;
```

Expand Down Expand Up @@ -74,8 +82,8 @@ added: v12.12.0
-->
The `module.syncBuiltinESMExports()` method updates all the live bindings for
builtin ES Modules to match the properties of the CommonJS exports. It does
not add or remove exported names from the ES Modules.
builtin [ES Modules][] to match the properties of the [CommonJS][] exports. It
does not add or remove exported names from the [ES Modules][].
```js
const fs = require('fs');
Expand Down Expand Up @@ -116,6 +124,14 @@ To enable source map parsing, Node.js must be run with the flag
[`NODE_V8_COVERAGE=dir`][].
```js
// module.mjs
// In an ECMAScript module
import { findSourceMap, SourceMap } from 'module';
```
```js
// module.cjs
// In a CommonJS module
const { findSourceMap, SourceMap } = require('module');
```
Expand Down Expand Up @@ -192,3 +208,6 @@ consists of the following keys:
[`Error.prepareStackTrace(error, trace)`]: https://v8.dev/docs/stack-trace-api#customizing-stack-traces
[`SourceMap`]: #module_class_module_sourcemap
[Source map v3 format]: https://sourcemaps.info/spec.html#h.mofvlxcwqzej
[`module`]: modules.html#modules_the_module_object
[CommonJS]: modules.html
[ES Modules]: esm.html

0 comments on commit 7dc3b74

Please sign in to comment.