{
  "type": "module",
  "source": "doc/api/modules.md",
  "modules": [
    {
      "textRaw": "Modules: CommonJS modules",
      "name": "module",
      "introduced_in": "v0.10.0",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>CommonJS modules are the original way to package JavaScript code for Node.js.\nNode.js also supports the <a href=\"esm.html\">ECMAScript modules</a> standard used by browsers\nand other JavaScript runtimes.</p>\n<p>In Node.js, each file is treated as a separate module. For\nexample, consider a file named <code>foo.js</code>:</p>\n<pre><code class=\"language-js\">const circle = require('./circle.js');\nconsole.log(`The area of a circle of radius 4 is ${circle.area(4)}`);\n</code></pre>\n<p>On the first line, <code>foo.js</code> loads the module <code>circle.js</code> that is in the same\ndirectory as <code>foo.js</code>.</p>\n<p>Here are the contents of <code>circle.js</code>:</p>\n<pre><code class=\"language-js\">const { PI } = Math;\n\nexports.area = (r) => PI * r ** 2;\n\nexports.circumference = (r) => 2 * PI * r;\n</code></pre>\n<p>The module <code>circle.js</code> has exported the functions <code>area()</code> and\n<code>circumference()</code>. Functions and objects are added to the root of a module\nby specifying additional properties on the special <code>exports</code> object.</p>\n<p>Variables local to the module will be private, because the module is wrapped\nin a function by Node.js (see <a href=\"#the-module-wrapper\">module wrapper</a>).\nIn this example, the variable <code>PI</code> is private to <code>circle.js</code>.</p>\n<p>The <code>module.exports</code> property can be assigned a new value (such as a function\nor object).</p>\n<p>Below, <code>bar.js</code> makes use of the <code>square</code> module, which exports a Square class:</p>\n<pre><code class=\"language-js\">const Square = require('./square.js');\nconst mySquare = new Square(2);\nconsole.log(`The area of mySquare is ${mySquare.area()}`);\n</code></pre>\n<p>The <code>square</code> module is defined in <code>square.js</code>:</p>\n<pre><code class=\"language-js\">// Assigning to exports will not modify module, must use module.exports\nmodule.exports = class Square {\n  constructor(width) {\n    this.width = width;\n  }\n\n  area() {\n    return this.width ** 2;\n  }\n};\n</code></pre>\n<p>The CommonJS module system is implemented in the <a href=\"module.html\"><code>module</code> core module</a>.</p>",
      "miscs": [
        {
          "textRaw": "Enabling",
          "name": "Enabling",
          "type": "misc",
          "desc": "<p>Node.js has two module systems: CommonJS modules and <a href=\"esm.html\">ECMAScript modules</a>.</p>\n<p>By default, Node.js will treat the following as CommonJS modules:</p>\n<ul>\n<li>\n<p>Files with a <code>.cjs</code> extension;</p>\n</li>\n<li>\n<p>Files with a <code>.js</code> extension when the nearest parent <code>package.json</code> file\ncontains a top-level field <a href=\"packages.html#type\"><code>\"type\"</code></a> with a value of <code>\"commonjs\"</code>.</p>\n</li>\n<li>\n<p>Files with a <code>.js</code> extension when the nearest parent <code>package.json</code> file\ndoesn't contain a top-level field <a href=\"packages.html#type\"><code>\"type\"</code></a>. Package authors should include\nthe <a href=\"packages.html#type\"><code>\"type\"</code></a> field, even in packages where all sources are CommonJS. Being\nexplicit about the <code>type</code> of the package will make things easier for build\ntools and loaders to determine how the files in the package should be\ninterpreted.</p>\n</li>\n<li>\n<p>Files with an extension that is not <code>.mjs</code>, <code>.cjs</code>, <code>.json</code>, <code>.node</code>, or <code>.js</code>\n(when the nearest parent <code>package.json</code> file contains a top-level field\n<a href=\"packages.html#type\"><code>\"type\"</code></a> with a value of <code>\"module\"</code>, those files will be recognized as\nCommonJS modules only if they are being included via <code>require()</code>, not when\nused as the command-line entry point of the program).</p>\n</li>\n</ul>\n<p>See <a href=\"packages.html#determining-module-system\">Determining module system</a> for more details.</p>\n<p>Calling <code>require()</code> always use the CommonJS module loader. Calling <code>import()</code>\nalways use the ECMAScript module loader.</p>"
        },
        {
          "textRaw": "Accessing the main module",
          "name": "Accessing the main module",
          "type": "misc",
          "desc": "<p>When a file is run directly from Node.js, <code>require.main</code> is set to its\n<code>module</code>. That means that it is possible to determine whether a file has been\nrun directly by testing <code>require.main === module</code>.</p>\n<p>For a file <code>foo.js</code>, this will be <code>true</code> if run via <code>node foo.js</code>, but\n<code>false</code> if run by <code>require('./foo')</code>.</p>\n<p>When the entry point is not a CommonJS module, <code>require.main</code> is <code>undefined</code>,\nand the main module is out of reach.</p>"
        },
        {
          "textRaw": "Package manager tips",
          "name": "Package manager tips",
          "type": "misc",
          "desc": "<p>The semantics of the Node.js <code>require()</code> function were designed to be general\nenough to support reasonable directory structures. Package manager programs\nsuch as <code>dpkg</code>, <code>rpm</code>, and <code>npm</code> will hopefully find it possible to build\nnative packages from Node.js modules without modification.</p>\n<p>Below we give a suggested directory structure that could work:</p>\n<p>Let's say that we wanted to have the folder at\n<code>/usr/lib/node/&#x3C;some-package>/&#x3C;some-version></code> hold the contents of a\nspecific version of a package.</p>\n<p>Packages can depend on one another. In order to install package <code>foo</code>, it\nmay be necessary to install a specific version of package <code>bar</code>. The <code>bar</code>\npackage may itself have dependencies, and in some cases, these may even collide\nor form cyclic dependencies.</p>\n<p>Because Node.js looks up the <code>realpath</code> of any modules it loads (that is, it\nresolves symlinks) and then <a href=\"#loading-from-node_modules-folders\">looks for their dependencies in <code>node_modules</code> folders</a>,\nthis situation can be resolved with the following architecture:</p>\n<ul>\n<li><code>/usr/lib/node/foo/1.2.3/</code>: Contents of the <code>foo</code> package, version 1.2.3.</li>\n<li><code>/usr/lib/node/bar/4.3.2/</code>: Contents of the <code>bar</code> package that <code>foo</code> depends\non.</li>\n<li><code>/usr/lib/node/foo/1.2.3/node_modules/bar</code>: Symbolic link to\n<code>/usr/lib/node/bar/4.3.2/</code>.</li>\n<li><code>/usr/lib/node/bar/4.3.2/node_modules/*</code>: Symbolic links to the packages that\n<code>bar</code> depends on.</li>\n</ul>\n<p>Thus, even if a cycle is encountered, or if there are dependency\nconflicts, every module will be able to get a version of its dependency\nthat it can use.</p>\n<p>When the code in the <code>foo</code> package does <code>require('bar')</code>, it will get the\nversion that is symlinked into <code>/usr/lib/node/foo/1.2.3/node_modules/bar</code>.\nThen, when the code in the <code>bar</code> package calls <code>require('quux')</code>, it'll get\nthe version that is symlinked into\n<code>/usr/lib/node/bar/4.3.2/node_modules/quux</code>.</p>\n<p>Furthermore, to make the module lookup process even more optimal, rather\nthan putting packages directly in <code>/usr/lib/node</code>, we could put them in\n<code>/usr/lib/node_modules/&#x3C;name>/&#x3C;version></code>. Then Node.js will not bother\nlooking for missing dependencies in <code>/usr/node_modules</code> or <code>/node_modules</code>.</p>\n<p>In order to make modules available to the Node.js REPL, it might be useful to\nalso add the <code>/usr/lib/node_modules</code> folder to the <code>$NODE_PATH</code> environment\nvariable. Since the module lookups using <code>node_modules</code> folders are all\nrelative, and based on the real path of the files making the calls to\n<code>require()</code>, the packages themselves can be anywhere.</p>"
        },
        {
          "textRaw": "All together",
          "name": "All together",
          "type": "misc",
          "desc": "<p>To get the exact filename that will be loaded when <code>require()</code> is called, use\nthe <code>require.resolve()</code> function.</p>\n<p>Putting together all of the above, here is the high-level algorithm\nin pseudocode of what <code>require()</code> does:</p>\n<pre>\nrequire(X) from module at path Y\n1. If X is a core module,\n   a. return the core module\n   b. STOP\n2. If X begins with '/'\n   a. set Y to be the file system root\n3. If X begins with './' or '/' or '../'\n   a. LOAD_AS_FILE(Y + X)\n   b. LOAD_AS_DIRECTORY(Y + X)\n   c. THROW \"not found\"\n4. If X begins with '#'\n   a. LOAD_PACKAGE_IMPORTS(X, dirname(Y))\n5. LOAD_PACKAGE_SELF(X, dirname(Y))\n6. LOAD_NODE_MODULES(X, dirname(Y))\n7. THROW \"not found\"\n\nLOAD_AS_FILE(X)\n1. If X is a file, load X as its file extension format. STOP\n2. If X.js is a file, load X.js as JavaScript text. STOP\n3. If X.json is a file, parse X.json to a JavaScript Object. STOP\n4. If X.node is a file, load X.node as binary addon. STOP\n\nLOAD_INDEX(X)\n1. If X/index.js is a file, load X/index.js as JavaScript text. STOP\n2. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP\n3. If X/index.node is a file, load X/index.node as binary addon. STOP\n\nLOAD_AS_DIRECTORY(X)\n1. If X/package.json is a file,\n   a. Parse X/package.json, and look for \"main\" field.\n   b. If \"main\" is a falsy value, GOTO 2.\n   c. let M = X + (json main field)\n   d. LOAD_AS_FILE(M)\n   e. LOAD_INDEX(M)\n   f. LOAD_INDEX(X) DEPRECATED\n   g. THROW \"not found\"\n2. LOAD_INDEX(X)\n\nLOAD_NODE_MODULES(X, START)\n1. let DIRS = NODE_MODULES_PATHS(START)\n2. for each DIR in DIRS:\n   a. LOAD_PACKAGE_EXPORTS(X, DIR)\n   b. LOAD_AS_FILE(DIR/X)\n   c. LOAD_AS_DIRECTORY(DIR/X)\n\nNODE_MODULES_PATHS(START)\n1. let PARTS = path split(START)\n2. let I = count of PARTS - 1\n3. let DIRS = []\n4. while I >= 0,\n   a. if PARTS[I] = \"node_modules\" CONTINUE\n   b. DIR = path join(PARTS[0 .. I] + \"node_modules\")\n   c. DIRS = DIR + DIRS\n   d. let I = I - 1\n5. return DIRS + GLOBAL_FOLDERS\n\nLOAD_PACKAGE_IMPORTS(X, DIR)\n1. Find the closest package scope SCOPE to DIR.\n2. If no scope was found, return.\n3. If the SCOPE/package.json \"imports\" is null or undefined, return.\n4. let MATCH = PACKAGE_IMPORTS_RESOLVE(X, pathToFileURL(SCOPE),\n  [\"node\", \"require\"]) <a href=\"esm.md#resolver-algorithm-specification\">defined in the ESM resolver</a>.\n5. RESOLVE_ESM_MATCH(MATCH).\n\nLOAD_PACKAGE_EXPORTS(X, DIR)\n1. Try to interpret X as a combination of NAME and SUBPATH where the name\n   may have a @scope/ prefix and the subpath begins with a slash (`/`).\n2. If X does not match this pattern or DIR/NAME/package.json is not a file,\n   return.\n3. Parse DIR/NAME/package.json, and look for \"exports\" field.\n4. If \"exports\" is null or undefined, return.\n5. let MATCH = PACKAGE_EXPORTS_RESOLVE(pathToFileURL(DIR/NAME), \".\" + SUBPATH,\n   `package.json` \"exports\", [\"node\", \"require\"]) <a href=\"esm.md#resolver-algorithm-specification\">defined in the ESM resolver</a>.\n6. RESOLVE_ESM_MATCH(MATCH)\n\nLOAD_PACKAGE_SELF(X, DIR)\n1. Find the closest package scope SCOPE to DIR.\n2. If no scope was found, return.\n3. If the SCOPE/package.json \"exports\" is null or undefined, return.\n4. If the SCOPE/package.json \"name\" is not the first segment of X, return.\n5. let MATCH = PACKAGE_EXPORTS_RESOLVE(pathToFileURL(SCOPE),\n   \".\" + X.slice(\"name\".length), `package.json` \"exports\", [\"node\", \"require\"])\n   <a href=\"esm.md#resolver-algorithm-specification\">defined in the ESM resolver</a>.\n6. RESOLVE_ESM_MATCH(MATCH)\n\nRESOLVE_ESM_MATCH(MATCH)\n1. let RESOLVED_PATH = fileURLToPath(MATCH)\n2. If the file at RESOLVED_PATH exists, load RESOLVED_PATH as its extension\n   format. STOP\n3. THROW \"not found\"\n</pre>"
        },
        {
          "textRaw": "Caching",
          "name": "Caching",
          "type": "misc",
          "desc": "<p>Modules are cached after the first time they are loaded. This means (among other\nthings) that every call to <code>require('foo')</code> will get exactly the same object\nreturned, if it would resolve to the same file.</p>\n<p>Provided <code>require.cache</code> is not modified, multiple calls to <code>require('foo')</code>\nwill not cause the module code to be executed multiple times. This is an\nimportant feature. With it, \"partially done\" objects can be returned, thus\nallowing transitive dependencies to be loaded even when they would cause cycles.</p>\n<p>To have a module execute code multiple times, export a function, and call that\nfunction.</p>",
          "miscs": [
            {
              "textRaw": "Module caching caveats",
              "name": "Module caching caveats",
              "type": "misc",
              "desc": "<p>Modules are cached based on their resolved filename. Since modules may resolve\nto a different filename based on the location of the calling module (loading\nfrom <code>node_modules</code> folders), it is not a <em>guarantee</em> that <code>require('foo')</code> will\nalways return the exact same object, if it would resolve to different files.</p>\n<p>Additionally, on case-insensitive file systems or operating systems, different\nresolved filenames can point to the same file, but the cache will still treat\nthem as different modules and will reload the file multiple times. For example,\n<code>require('./foo')</code> and <code>require('./FOO')</code> return two different objects,\nirrespective of whether or not <code>./foo</code> and <code>./FOO</code> are the same file.</p>"
            }
          ]
        },
        {
          "textRaw": "Core modules",
          "name": "Core modules",
          "type": "misc",
          "meta": {
            "changes": [
              {
                "version": [
                  "v16.0.0",
                  "v14.18.0"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/37246",
                "description": "Added `node:` import support to `require(...)`."
              }
            ]
          },
          "desc": "<p>Node.js has several modules compiled into the binary. These modules are\ndescribed in greater detail elsewhere in this documentation.</p>\n<p>The core modules are defined within the Node.js source and are located in the\n<code>lib/</code> folder.</p>\n<p>Core modules can be identified using the <code>node:</code> prefix, in which case\nit bypasses the <code>require</code> cache. For instance, <code>require('node:http')</code> will\nalways return the built in HTTP module, even if there is <code>require.cache</code> entry\nby that name.</p>\n<p>Some core modules are always preferentially loaded if their identifier is\npassed to <code>require()</code>. For instance, <code>require('http')</code> will always\nreturn the built-in HTTP module, even if there is a file by that name. The list\nof core modules that can be loaded without using the <code>node:</code> prefix is exposed\nas <a href=\"module.html#modulebuiltinmodules\"><code>module.builtinModules</code></a>.</p>"
        },
        {
          "textRaw": "Cycles",
          "name": "Cycles",
          "type": "misc",
          "desc": "<p>When there are circular <code>require()</code> calls, a module might not have finished\nexecuting when it is returned.</p>\n<p>Consider this situation:</p>\n<p><code>a.js</code>:</p>\n<pre><code class=\"language-js\">console.log('a starting');\nexports.done = false;\nconst b = require('./b.js');\nconsole.log('in a, b.done = %j', b.done);\nexports.done = true;\nconsole.log('a done');\n</code></pre>\n<p><code>b.js</code>:</p>\n<pre><code class=\"language-js\">console.log('b starting');\nexports.done = false;\nconst a = require('./a.js');\nconsole.log('in b, a.done = %j', a.done);\nexports.done = true;\nconsole.log('b done');\n</code></pre>\n<p><code>main.js</code>:</p>\n<pre><code class=\"language-js\">console.log('main starting');\nconst a = require('./a.js');\nconst b = require('./b.js');\nconsole.log('in main, a.done = %j, b.done = %j', a.done, b.done);\n</code></pre>\n<p>When <code>main.js</code> loads <code>a.js</code>, then <code>a.js</code> in turn loads <code>b.js</code>. At that\npoint, <code>b.js</code> tries to load <code>a.js</code>. In order to prevent an infinite\nloop, an <strong>unfinished copy</strong> of the <code>a.js</code> exports object is returned to the\n<code>b.js</code> module. <code>b.js</code> then finishes loading, and its <code>exports</code> object is\nprovided to the <code>a.js</code> module.</p>\n<p>By the time <code>main.js</code> has loaded both modules, they're both finished.\nThe output of this program would thus be:</p>\n<pre><code class=\"language-console\">$ node main.js\nmain starting\na starting\nb starting\nin b, a.done = false\nb done\nin a, b.done = true\na done\nin main, a.done = true, b.done = true\n</code></pre>\n<p>Careful planning is required to allow cyclic module dependencies to work\ncorrectly within an application.</p>"
        },
        {
          "textRaw": "File modules",
          "name": "File modules",
          "type": "misc",
          "desc": "<p>If the exact filename is not found, then Node.js will attempt to load the\nrequired filename with the added extensions: <code>.js</code>, <code>.json</code>, and finally\n<code>.node</code>. When loading a file that has a different extension (e.g. <code>.cjs</code>), its\nfull name must be passed to <code>require()</code>, including its file extension (e.g.\n<code>require('./file.cjs')</code>).</p>\n<p><code>.json</code> files are parsed as JSON text files, <code>.node</code> files are interpreted as\ncompiled addon modules loaded with <code>process.dlopen()</code>. Files using any other\nextension (or no extension at all) are parsed as JavaScript text files. Refer to\nthe <a href=\"packages.html#determining-module-system\">Determining module system</a> section to understand what parse goal will be\nused.</p>\n<p>A required module prefixed with <code>'/'</code> is an absolute path to the file. For\nexample, <code>require('/home/marco/foo.js')</code> will load the file at\n<code>/home/marco/foo.js</code>.</p>\n<p>A required module prefixed with <code>'./'</code> is relative to the file calling\n<code>require()</code>. That is, <code>circle.js</code> must be in the same directory as <code>foo.js</code> for\n<code>require('./circle')</code> to find it.</p>\n<p>Without a leading <code>'/'</code>, <code>'./'</code>, or <code>'../'</code> to indicate a file, the module must\neither be a core module or is loaded from a <code>node_modules</code> folder.</p>\n<p>If the given path does not exist, <code>require()</code> will throw a\n<a href=\"errors.html#module_not_found\"><code>MODULE_NOT_FOUND</code></a> error.</p>"
        },
        {
          "textRaw": "Folders as modules",
          "name": "Folders as modules",
          "type": "misc",
          "stability": 3,
          "stabilityText": "Legacy: Use [subpath exports][] or [subpath imports][] instead.",
          "desc": "<p>There are three ways in which a folder may be passed to <code>require()</code> as\nan argument.</p>\n<p>The first is to create a <a href=\"packages.html#nodejs-packagejson-field-definitions\"><code>package.json</code></a> file in the root of the folder,\nwhich specifies a <code>main</code> module. An example <a href=\"packages.html#nodejs-packagejson-field-definitions\"><code>package.json</code></a> file might\nlook like this:</p>\n<pre><code class=\"language-json\">{ \"name\" : \"some-library\",\n  \"main\" : \"./lib/some-library.js\" }\n</code></pre>\n<p>If this was in a folder at <code>./some-library</code>, then\n<code>require('./some-library')</code> would attempt to load\n<code>./some-library/lib/some-library.js</code>.</p>\n<p>If there is no <a href=\"packages.html#nodejs-packagejson-field-definitions\"><code>package.json</code></a> file present in the directory, or if the\n<a href=\"packages.html#main\"><code>\"main\"</code></a> entry is missing or cannot be resolved, then Node.js\nwill attempt to load an <code>index.js</code> or <code>index.node</code> file out of that\ndirectory. For example, if there was no <a href=\"packages.html#nodejs-packagejson-field-definitions\"><code>package.json</code></a> file in the previous\nexample, then <code>require('./some-library')</code> would attempt to load:</p>\n<ul>\n<li><code>./some-library/index.js</code></li>\n<li><code>./some-library/index.node</code></li>\n</ul>\n<p>If these attempts fail, then Node.js will report the entire module as missing\nwith the default error:</p>\n<pre><code class=\"language-console\">Error: Cannot find module 'some-library'\n</code></pre>\n<p>In all three above cases, an <code>import('./some-library')</code> call would result in a\n<a href=\"errors.html#err_unsupported_dir_import\"><code>ERR_UNSUPPORTED_DIR_IMPORT</code></a> error. Using package <a href=\"packages.html#subpath-exports\">subpath exports</a> or\n<a href=\"packages.html#subpath-imports\">subpath imports</a> can provide the same containment organization benefits as\nfolders as modules, and work for both <code>require</code> and <code>import</code>.</p>"
        },
        {
          "textRaw": "Loading from `node_modules` folders",
          "name": "Loading from `node_modules` folders",
          "type": "misc",
          "desc": "<p>If the module identifier passed to <code>require()</code> is not a\n<a href=\"#core-modules\">core</a> module, and does not begin with <code>'/'</code>, <code>'../'</code>, or\n<code>'./'</code>, then Node.js starts at the directory of the current module, and\nadds <code>/node_modules</code>, and attempts to load the module from that location.\nNode.js will not append <code>node_modules</code> to a path already ending in\n<code>node_modules</code>.</p>\n<p>If it is not found there, then it moves to the parent directory, and so\non, until the root of the file system is reached.</p>\n<p>For example, if the file at <code>'/home/ry/projects/foo.js'</code> called\n<code>require('bar.js')</code>, then Node.js would look in the following locations, in\nthis order:</p>\n<ul>\n<li><code>/home/ry/projects/node_modules/bar.js</code></li>\n<li><code>/home/ry/node_modules/bar.js</code></li>\n<li><code>/home/node_modules/bar.js</code></li>\n<li><code>/node_modules/bar.js</code></li>\n</ul>\n<p>This allows programs to localize their dependencies, so that they do not\nclash.</p>\n<p>It is possible to require specific files or sub modules distributed with a\nmodule by including a path suffix after the module name. For instance\n<code>require('example-module/path/to/file')</code> would resolve <code>path/to/file</code>\nrelative to where <code>example-module</code> is located. The suffixed path follows the\nsame module resolution semantics.</p>"
        },
        {
          "textRaw": "Loading from the global folders",
          "name": "Loading from the global folders",
          "type": "misc",
          "desc": "<p>If the <code>NODE_PATH</code> environment variable is set to a colon-delimited list\nof absolute paths, then Node.js will search those paths for modules if they\nare not found elsewhere.</p>\n<p>On Windows, <code>NODE_PATH</code> is delimited by semicolons (<code>;</code>) instead of colons.</p>\n<p><code>NODE_PATH</code> was originally created to support loading modules from\nvarying paths before the current <a href=\"#all-together\">module resolution</a> algorithm was defined.</p>\n<p><code>NODE_PATH</code> is still supported, but is less necessary now that the Node.js\necosystem has settled on a convention for locating dependent modules.\nSometimes deployments that rely on <code>NODE_PATH</code> show surprising behavior\nwhen people are unaware that <code>NODE_PATH</code> must be set. Sometimes a\nmodule's dependencies change, causing a different version (or even a\ndifferent module) to be loaded as the <code>NODE_PATH</code> is searched.</p>\n<p>Additionally, Node.js will search in the following list of GLOBAL_FOLDERS:</p>\n<ul>\n<li>1: <code>$HOME/.node_modules</code></li>\n<li>2: <code>$HOME/.node_libraries</code></li>\n<li>3: <code>$PREFIX/lib/node</code></li>\n</ul>\n<p>Where <code>$HOME</code> is the user's home directory, and <code>$PREFIX</code> is the Node.js\nconfigured <code>node_prefix</code>.</p>\n<p>These are mostly for historic reasons.</p>\n<p>It is strongly encouraged to place dependencies in the local <code>node_modules</code>\nfolder. These will be loaded faster, and more reliably.</p>"
        },
        {
          "textRaw": "The module wrapper",
          "name": "The module wrapper",
          "type": "misc",
          "desc": "<p>Before a module's code is executed, Node.js will wrap it with a function\nwrapper that looks like the following:</p>\n<pre><code class=\"language-js\">(function(exports, require, module, __filename, __dirname) {\n// Module code actually lives in here\n});\n</code></pre>\n<p>By doing this, Node.js achieves a few things:</p>\n<ul>\n<li>It keeps top-level variables (defined with <code>var</code>, <code>const</code>, or <code>let</code>) scoped to\nthe module rather than the global object.</li>\n<li>It helps to provide some global-looking variables that are actually specific\nto the module, such as:\n<ul>\n<li>The <code>module</code> and <code>exports</code> objects that the implementor can use to export\nvalues from the module.</li>\n<li>The convenience variables <code>__filename</code> and <code>__dirname</code>, containing the\nmodule's absolute filename and directory path.</li>\n</ul>\n</li>\n</ul>"
        }
      ],
      "modules": [
        {
          "textRaw": "The `.mjs` extension",
          "name": "the_`.mjs`_extension",
          "desc": "<p>Due to the synchronous nature of <code>require()</code>, it is not possible to use it to\nload ECMAScript module files. Attempting to do so will throw a\n<a href=\"errors.html#err_require_esm\"><code>ERR_REQUIRE_ESM</code></a> error. Use <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import\"><code>import()</code></a> instead.</p>\n<p>The <code>.mjs</code> extension is reserved for 