{ "type": "module", "source": "doc/api/module.md", "modules": [ { "textRaw": "Modules: `module` API", "name": "modules:_`module`_api", "introduced_in": "v0.3.7", "modules": [ { "textRaw": "The `Module` object", "name": "the_`module`_object", "desc": "\n

Provides general utility methods when interacting with instances of\nModule, the module variable often seen in CommonJS modules. Accessed\nvia import 'module' or require('module').

", "properties": [ { "textRaw": "`builtinModules` {string[]}", "type": "string[]", "name": "builtinModules", "meta": { "added": [ "v9.3.0", "v8.10.0", "v6.13.0" ], "changes": [] }, "desc": "

A list of the names of all modules provided by Node.js. Can be used to verify\nif a module is maintained by a third party or not.

\n

module in this context isn't the same object that's provided\nby the module wrapper. To access it, require the Module module:

\n
// module.mjs\n// In an ECMAScript module\nimport { builtinModules as builtin } from 'module';\n
\n
// module.cjs\n// In a CommonJS module\nconst builtin = require('module').builtinModules;\n
" } ], "methods": [ { "textRaw": "`module.createRequire(filename)`", "type": "method", "name": "createRequire", "meta": { "added": [ "v12.2.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {require} Require function", "name": "return", "type": "require", "desc": "Require function" }, "params": [ { "textRaw": "`filename` {string|URL} Filename to be used to construct the require function. Must be a file URL object, file URL string, or absolute path string.", "name": "filename", "type": "string|URL", "desc": "Filename to be used to construct the require function. Must be a file URL object, file URL string, or absolute path string." } ] } ], "desc": "
import { createRequire } from 'module';\nconst require = createRequire(import.meta.url);\n\n// sibling-module.js is a CommonJS module.\nconst siblingModule = require('./sibling-module');\n
" }, { "textRaw": "`module.createRequireFromPath(filename)`", "type": "method", "name": "createRequireFromPath", "meta": { "added": [ "v10.12.0" ], "deprecated": [ "v12.2.0" ], "changes": [] }, "stability": 0, "stabilityText": "Deprecated: Please use [`createRequire()`][] instead.", "signatures": [ { "return": { "textRaw": "Returns: {require} Require function", "name": "return", "type": "require", "desc": "Require function" }, "params": [ { "textRaw": "`filename` {string} Filename to be used to construct the relative require function.", "name": "filename", "type": "string", "desc": "Filename to be used to construct the relative require function." } ] } ], "desc": "
const { createRequireFromPath } = require('module');\nconst requireUtil = createRequireFromPath('../src/utils/');\n\n// Require `../src/utils/some-tool`\nrequireUtil('./some-tool');\n
" }, { "textRaw": "`module.syncBuiltinESMExports()`", "type": "method", "name": "syncBuiltinESMExports", "meta": { "added": [ "v12.12.0" ], "changes": [] }, "signatures": [ { "params": [] } ], "desc": "

The module.syncBuiltinESMExports() method updates all the live bindings for\nbuiltin ES Modules to match the properties of the CommonJS exports. It\ndoes not add or remove exported names from the ES Modules.

\n
const fs = require('fs');\nconst { syncBuiltinESMExports } = require('module');\n\nfs.readFile = null;\n\ndelete fs.readFileSync;\n\nfs.newAPI = function newAPI() {\n  // ...\n};\n\nsyncBuiltinESMExports();\n\nimport('fs').then((esmFS) => {\n  assert.strictEqual(esmFS.readFile, null);\n  assert.strictEqual('readFileSync' in fs, true);\n  assert.strictEqual(esmFS.newAPI, undefined);\n});\n
" } ], "type": "module", "displayName": "The `Module` object" }, { "textRaw": "Source map v3 support", "name": "source_map_v3_support", "meta": { "added": [ "v13.7.0", "v12.17.0" ], "changes": [] }, "stability": 1, "stabilityText": "Experimental", "desc": "

Helpers for interacting with the source map cache. This cache is\npopulated when source map parsing is enabled and\nsource map include directives are found in a modules' footer.

\n

To enable source map parsing, Node.js must be run with the flag\n--enable-source-maps, or with code coverage enabled by setting\nNODE_V8_COVERAGE=dir.

\n
// module.mjs\n// In an ECMAScript module\nimport { findSourceMap, SourceMap } from 'module';\n
\n
// module.cjs\n// In a CommonJS module\nconst { findSourceMap, SourceMap } = require('module');\n
", "methods": [ { "textRaw": "`module.findSourceMap(path[, error])`", "type": "method", "name": "findSourceMap", "meta": { "added": [ "v13.7.0", "v12.17.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {module.SourceMap}", "name": "return", "type": "module.SourceMap" }, "params": [ { "textRaw": "`path` {string}", "name": "path", "type": "string" }, { "textRaw": "`error` {Error}", "name": "error", "type": "Error" } ] } ], "desc": "

path is the resolved path for the file for which a corresponding source map\nshould be fetched.

\n

The error instance should be passed as the second parameter to findSourceMap\nin exceptional flows, such as when an overridden\nError.prepareStackTrace(error, trace) is invoked. Modules are not added to\nthe module cache until they are successfully loaded. In these cases, source maps\nare associated with the error instance along with the path.

" } ], "classes": [ { "textRaw": "Class: `module.SourceMap`", "type": "class", "name": "module.SourceMap", "meta": { "added": [ "v13.7.0", "v12.17.0" ], "changes": [] }, "properties": [ { "textRaw": "`payload` Returns: {Object}", "type": "Object", "name": "return", "desc": "

Getter for the payload used to construct the SourceMap instance.

" } ], "methods": [ { "textRaw": "`sourceMap.findEntry(lineNumber, columnNumber)`", "type": "method", "name": "findEntry", "signatures": [ { "return": { "textRaw": "Returns: {Object}", "name": "return", "type": "Object" }, "params": [ { "textRaw": "`lineNumber` {number}", "name": "lineNumber", "type": "number" }, { "textRaw": "`columnNumber` {number}", "name": "columnNumber", "type": "number" } ] } ], "desc": "

Given a line number and column number in the generated source file, returns\nan object representing the position in the original file. The object returned\nconsists of the following keys:

\n" } ], "signatures": [ { "params": [ { "textRaw": "`payload` {Object}", "name": "payload", "type": "Object" } ], "desc": "

Creates a new sourceMap instance.

\n

payload is an object with keys matching the Source map v3 format:

\n" } ] } ], "type": "module", "displayName": "Source map v3 support" } ], "type": "module", "displayName": "Modules: `module` API" } ] }