mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
doc: replace node:modules documentation header
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
09feba74c8
commit
bdc75900ee
1 file changed
+34
-30
+34
-30
@@ -2,19 +2,30 @@
|
||||
|
||||
<!--introduced_in=v12.20.0-->
|
||||
|
||||
> Stability: 2 - Stable
|
||||
|
||||
<!-- source_link=lib/module.js -->
|
||||
|
||||
The `node:module` module provides utilities for interacting with the Node.js
|
||||
module system.
|
||||
|
||||
It can be accessed using:
|
||||
|
||||
```mjs
|
||||
import module from 'node:module';
|
||||
```
|
||||
|
||||
## Class: `Module`
|
||||
|
||||
<!-- YAML
|
||||
added: v0.3.7
|
||||
added: v0.3.5
|
||||
-->
|
||||
|
||||
## The `Module` object
|
||||
`module` objects in [CommonJS][] modules are instances of this class.
|
||||
|
||||
* Type: {Object}
|
||||
See the CommonJS documentation for [the `module` object][].
|
||||
|
||||
Provides general utility methods when interacting with instances of
|
||||
`Module`, the [`module`][] variable often seen in [CommonJS][] modules. Accessed
|
||||
via `import 'node:module'` or `require('node:module')`.
|
||||
|
||||
### `module.builtinModules`
|
||||
## `module.builtinModules`
|
||||
|
||||
<!-- YAML
|
||||
added:
|
||||
@@ -29,25 +40,18 @@ changes:
|
||||
|
||||
* Type: {string\[]}
|
||||
|
||||
A list of the names of all modules provided by Node.js. Can be used to verify
|
||||
if a module is maintained by a third party or not.
|
||||
|
||||
`module` in this context isn't the same object that's provided
|
||||
by the [module wrapper][]. To access it, require the `Module` module:
|
||||
A list of the names of all modules provided by Node.js.
|
||||
|
||||
```mjs
|
||||
// module.mjs
|
||||
// In an ECMAScript module
|
||||
import { builtinModules as builtin } from 'node:module';
|
||||
import { builtinModules } from 'node:module';
|
||||
console.log(builtinModules.filter((name) => name.startsWith('path')));
|
||||
// Prints: [ 'path', 'path/posix', 'path/win32' ]
|
||||
```
|
||||
|
||||
```cjs
|
||||
// module.cjs
|
||||
// In a CommonJS module
|
||||
const builtin = require('node:module').builtinModules;
|
||||
```
|
||||
To test whether a module name corresponds to a builtin module, use
|
||||
[`module.isBuiltin()`][].
|
||||
|
||||
### `module.createRequire(filename)`
|
||||
## `module.createRequire(filename)`
|
||||
|
||||
<!-- YAML
|
||||
added: v12.2.0
|
||||
@@ -66,7 +70,7 @@ const require = createRequire(import.meta.url);
|
||||
const siblingModule = require('./sibling-module');
|
||||
```
|
||||
|
||||
### `module.findPackageJSON(specifier[, base])`
|
||||
## `module.findPackageJSON(specifier[, base])`
|
||||
|
||||
<!-- YAML
|
||||
added:
|
||||
@@ -154,7 +158,7 @@ findPackageJSON('@foo/qux', __filename);
|
||||
// '/path/to/project/packages/qux/package.json'
|
||||
```
|
||||
|
||||
### `module.isBuiltin(moduleName)`
|
||||
## `module.isBuiltin(moduleName)`
|
||||
|
||||
<!-- YAML
|
||||
added:
|
||||
@@ -172,7 +176,7 @@ isBuiltin('fs'); // true
|
||||
isBuiltin('wss'); // false
|
||||
```
|
||||
|
||||
### `module.register(specifier[, parentURL][, options])`
|
||||
## `module.register(specifier[, parentURL][, options])`
|
||||
|
||||
<!-- YAML
|
||||
added:
|
||||
@@ -220,7 +224,7 @@ resolution and loading behavior. See [Customization hooks][].
|
||||
|
||||
This feature requires `--allow-worker` if used with the [Permission Model][].
|
||||
|
||||
### `module.registerHooks(options)`
|
||||
## `module.registerHooks(options)`
|
||||
|
||||
<!-- YAML
|
||||
added:
|
||||
@@ -249,7 +253,7 @@ Register [hooks][] that customize Node.js module resolution and loading behavior
|
||||
See [Customization hooks][]. The returned object can be used to
|
||||
[deregister the hooks][deregistration of synchronous customization hooks].
|
||||
|
||||
### `module.stripTypeScriptTypes(code[, options])`
|
||||
## `module.stripTypeScriptTypes(code[, options])`
|
||||
|
||||
<!-- YAML
|
||||
added:
|
||||
@@ -314,7 +318,7 @@ console.log(strippedCode);
|
||||
// Prints: const a = 1\n\n//# sourceURL=source.ts;
|
||||
```
|
||||
|
||||
### `module.syncBuiltinESMExports()`
|
||||
## `module.syncBuiltinESMExports()`
|
||||
|
||||
<!-- YAML
|
||||
added: v12.12.0
|
||||
@@ -2073,9 +2077,9 @@ returned object contains the following keys:
|
||||
[`module.enableCompileCache()`]: #moduleenablecompilecacheoptions
|
||||
[`module.flushCompileCache()`]: #moduleflushcompilecache
|
||||
[`module.getCompileCacheDir()`]: #modulegetcompilecachedir
|
||||
[`module.isBuiltin()`]: #moduleisbuiltinmodulename
|
||||
[`module.registerHooks()`]: #moduleregisterhooksoptions
|
||||
[`module.setSourceMapsSupport()`]: #modulesetsourcemapssupportenabled-options
|
||||
[`module`]: #the-module-object
|
||||
[`os.tmpdir()`]: os.md#ostmpdir
|
||||
[`register`]: #moduleregisterspecifier-parenturl-options
|
||||
[`util.TextDecoder`]: util.md#class-utiltextdecoder
|
||||
@@ -2088,11 +2092,11 @@ returned object contains the following keys:
|
||||
[hooks]: #customization-hooks
|
||||
[load hook]: #synchronous-loadurl-context-nextload
|
||||
[module compile cache]: #module-compile-cache
|
||||
[module wrapper]: modules.md#the-module-wrapper
|
||||
[realm]: https://tc39.es/ecma262/#realm
|
||||
[resolve hook]: #synchronous-resolvespecifier-context-nextresolve
|
||||
[source map include directives]: https://tc39.es/ecma426/#sec-linking-generated-code
|
||||
[synchronous hook functions]: #hook-functions-accepted-by-moduleregisterhooks
|
||||
[the `module` object]: modules.md#the-module-object
|
||||
[the documentation of `Worker`]: worker_threads.md#new-workerfilename-options
|
||||
[transferable objects]: worker_threads.md#portpostmessagevalue-transferlist
|
||||
[type-stripping]: typescript.md#type-stripping
|
||||
Reference in new issue
Block a user