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>
pull/19296/merge
Vse Mozhet Byt 2018-03-24 14:22:19 +02:00
parent 275a728353
commit 610dd79956
1 changed files with 37 additions and 0 deletions

View File

@ -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