{ "type": "module", "source": "doc/api/module.md", "modules": [ { "textRaw": "Modules: `module` API", "name": "modules:_`module`_api", "introduced_in": "v12.20.0", "meta": { "added": [ "v0.3.7" ], "changes": [] }, "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.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 assert = require('assert');\nconst { syncBuiltinESMExports } = require('module');\n\nfs.readFile = newAPI;\n\ndelete fs.readFileSync;\n\nfunction newAPI() {\n  // ...\n}\n\nfs.newAPI = newAPI;\n\nsyncBuiltinESMExports();\n\nimport('fs').then((esmFS) => {\n  // It syncs the existing readFile property with the new value\n  assert.strictEqual(esmFS.readFile, newAPI);\n  // readFileSync has been deleted from the required fs\n  assert.strictEqual('readFileSync' in fs, false);\n  // syncBuiltinESMExports() does not remove readFileSync from esmFS\n  assert.strictEqual('readFileSync' in esmFS, true);\n  // syncBuiltinESMExports() does not add names\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
\n\n

", "methods": [ { "textRaw": "`module.findSourceMap(path)`", "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" } ] } ], "desc": "

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

" } ], "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" } ] }