From 4532a8913d9b9ee6b8b414f063882708cbbdb381 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sat, 24 Mar 2018 14:22:19 +0200 Subject: [PATCH] doc: add `require.main` to `require` properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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 Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso --- doc/api/modules.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/doc/api/modules.md b/doc/api/modules.md index 2930f2af68e095..aa03b414c35dfa 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 + + +* {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 +``` + + +```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])