Skip to content

Commit

Permalink
doc: document that require.main may be undefined
Browse files Browse the repository at this point in the history
PR-URL: #41384
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Adrian Estrada <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
  • Loading branch information
aduh95 authored and danielleadams committed Feb 1, 2022
1 parent 71bc352 commit 04a81b3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
`false` if run by `require('./foo')`.

Because `module` provides a `filename` property (normally equivalent to
`__filename`), the entry point of the current application can be obtained
by checking `require.main.filename`.
When the entry point is not a CommonJS module, `require.main` is `undefined`,
and the main module is out of reach.

## Package manager tips

Expand Down Expand Up @@ -716,10 +715,11 @@ extensions gets slower with each registered extension.
added: v0.1.17
-->

* {module}
* {module | undefined}

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).

In `entry.js` script:
Expand Down

0 comments on commit 04a81b3

Please sign in to comment.