Skip to content

Commit

Permalink
module: add docs signature for register
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Aug 20, 2023
1 parent 5026293 commit 5ec4fd3
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,27 @@ isBuiltin('fs'); // true
isBuiltin('wss'); // false
```
### `module.register()`
### `module.register(specifier[, parentURL[, options]])`
<!-- YAML
added: REPLACEME
-->
In addition to using the `--experimental-loader` option in the CLI,
loaders can be registered programmatically using the
`module.register()` method.
* `specifier` {string} Customization hooks to be registered; this should be the
same string that would be passed to `import()`, except that if it is relative,
it is resolved relative to `parentURL`.
* `parentURL` {string} If you want to resolve `specifier` relative to a base
URL, such as `import.meta.url`, you can pass that URL here. **Default:**
`'data:'`
* `options` {Object}
* `data` {any} Any arbitrary, cloneable JavaScript value to pass into the
[`initialize`][] hook.
* `transferList` {Object\[]} [transferrable objects][] to be passed into the
`initialize` hook.
* Returns: {any} returns whatever was returned by the `initialize` hook.
Register a module that exports hooks that customize Node.js’ module resolution
and loading behavior.
```mjs
import { register } from 'node:module';
Expand Down Expand Up @@ -390,3 +402,4 @@ returned object contains the following keys:
[`module`]: modules.md#the-module-object
[module wrapper]: modules.md#the-module-wrapper
[source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx
[transferrable objects]: worker_threads.md#portpostmessagevalue-transferlist

0 comments on commit 5ec4fd3

Please sign in to comment.