doc: process: Document process.mainModule
authorJan Krems <jan.krems@gmail.com>
Sun, 22 Jun 2014 00:09:04 +0000 (17:09 -0700)
committerFedor Indutny <fedor@indutny.com>
Tue, 24 Jun 2014 16:21:25 +0000 (20:21 +0400)
Instrumentation code might need to find out the entry point of the
process in a global context.
Documenting the existing process.mainModule to officially support this.

Fixes #7808

Signed-off-by: Fedor Indutny <fedor@indutny.com>
doc/api/process.markdown

index eac1d4e..8c914f3 100644 (file)
@@ -716,4 +716,16 @@ a diff reading, useful for benchmarks and measuring intervals:
       // benchmark took 1000000527 nanoseconds
     }, 1000);
 
+
+## process.mainModule
+
+Alternate way to retrieve
+[`require.main`](modules.html#modules_accessing_the_main_module).
+The difference is that if the main module changes at runtime, `require.main`
+might still refer to the original main module in modules that were required
+before the change occurred. Generally it's safe to assume that the two refer
+to the same module.
+
+As with `require.main`, it will be `undefined` if there was no entry script.
+
 [EventEmitter]: events.html#events_class_events_eventemitter