Skip to content

Commit 4532a89

Browse files
vsemozhetbyttargos
authored andcommitted
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: #19573 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 1e8ece1 commit 4532a89

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

doc/api/modules.md

+37
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,43 @@ filename scales linearly with the number of registered extensions.
600600
In other words, adding extensions slows down the module loader and
601601
should be discouraged.
602602

603+
#### require.main
604+
<!-- YAML
605+
added: v0.1.17
606+
-->
607+
608+
* {Object}
609+
610+
The `Module` object representing the entry script loaded when the Node.js
611+
process launched.
612+
See ["Accessing the main module"](#modules_accessing_the_main_module).
613+
614+
In `entry.js` script:
615+
616+
```js
617+
console.log(require.main);
618+
```
619+
620+
```sh
621+
node entry.js
622+
```
623+
624+
<!-- eslint-skip -->
625+
```js
626+
Module {
627+
id: '.',
628+
exports: {},
629+
parent: null,
630+
filename: '/absolute/path/to/entry.js',
631+
loaded: false,
632+
children: [],
633+
paths:
634+
[ '/absolute/path/to/node_modules',
635+
'/absolute/path/node_modules',
636+
'/absolute/node_modules',
637+
'/node_modules' ] }
638+
```
639+
603640
#### require.resolve(request[, options])
604641
<!-- YAML
605642
added: v0.3.0

0 commit comments

Comments
 (0)