doc: document that require.main
may be undefined
PR-URL: https://github.com/nodejs/node/pull/41384 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Adrian Estrada <edsadr@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
This commit is contained in:
parent
b4908054d0
commit
090cdb66c0
@ -74,9 +74,8 @@ run directly by testing `require.main === module`.
|
|||||||
For a file `foo.js`, this will be `true` if run via `node foo.js`, but
|
For a file `foo.js`, this will be `true` if run via `node foo.js`, but
|
||||||
`false` if run by `require('./foo')`.
|
`false` if run by `require('./foo')`.
|
||||||
|
|
||||||
Because `module` provides a `filename` property (normally equivalent to
|
When the entry point is not a CommonJS module, `require.main` is `undefined`,
|
||||||
`__filename`), the entry point of the current application can be obtained
|
and the main module is out of reach.
|
||||||
by checking `require.main.filename`.
|
|
||||||
|
|
||||||
## Package manager tips
|
## Package manager tips
|
||||||
|
|
||||||
@ -718,10 +717,11 @@ extensions gets slower with each registered extension.
|
|||||||
added: v0.1.17
|
added: v0.1.17
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* {module}
|
* {module | undefined}
|
||||||
|
|
||||||
The `Module` object representing the entry script loaded when the Node.js
|
The `Module` object representing the entry script loaded when the Node.js
|
||||||
process launched.
|
process launched, or `undefined` if the entry point of the program is not a
|
||||||
|
CommonJS module.
|
||||||
See ["Accessing the main module"](#accessing-the-main-module).
|
See ["Accessing the main module"](#accessing-the-main-module).
|
||||||
|
|
||||||
In `entry.js` script:
|
In `entry.js` script:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user