summaryrefslogtreecommitdiff
path: root/doc/api/modules.md
diff options
context:
space:
mode:
authorVse Mozhet Byt <vsemozhetbyt@gmail.com>2018-03-24 14:22:19 +0200
committerVse Mozhet Byt <vsemozhetbyt@gmail.com>2018-03-24 18:26:35 +0200
commit610dd79956e582aa4c189092d3048f0d11c757a3 (patch)
tree30ff904b3a55d8b2343fe6cc7e66b60e02d47502 /doc/api/modules.md
parent275a7283531bf7c7e05179db7f845881d3b5b626 (diff)
downloadandroid-node-v8-610dd79956e582aa4c189092d3048f0d11c757a3.tar.gz
android-node-v8-610dd79956e582aa4c189092d3048f0d11c757a3.tar.bz2
android-node-v8-610dd79956e582aa4c189092d3048f0d11c757a3.zip
doc: add `require.main` to `require` properties
`require.main` was documented in a non-standard way. With this PR, the previous section is left as is to not break all the possible link references inside and outside Node.js docs. A standard section is added to the `require` properties with a reference to the old description. PR-URL: https://github.com/nodejs/node/pull/19573 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'doc/api/modules.md')
-rw-r--r--doc/api/modules.md37
1 files changed, 37 insertions, 0 deletions
diff --git a/doc/api/modules.md b/doc/api/modules.md
index 2930f2af68..aa03b414c3 100644
--- a/doc/api/modules.md
+++ b/doc/api/modules.md
@@ -600,6 +600,43 @@ filename scales linearly with the number of registered extensions.
In other words, adding extensions slows down the module loader and
should be discouraged.
+#### require.main
+<!-- YAML
+added: v0.1.17
+-->
+
+* {Object}
+
+The `Module` object representing the entry script loaded when the Node.js
+process launched.
+See ["Accessing the main module"](#modules_accessing_the_main_module).
+
+In `entry.js` script:
+
+```js
+console.log(require.main);
+```
+
+```sh
+node entry.js
+```
+
+<!-- eslint-skip -->
+```js
+Module {
+ id: '.',
+ exports: {},
+ parent: null,
+ filename: '/absolute/path/to/entry.js',
+ loaded: false,
+ children: [],
+ paths:
+ [ '/absolute/path/to/node_modules',
+ '/absolute/path/node_modules',
+ '/absolute/node_modules',
+ '/node_modules' ] }
+```
+
#### require.resolve(request[, options])
<!-- YAML
added: v0.3.0