Utility functions for determining module execution context.
- Description:
Utility functions for determining module execution context.
- Source:
Methods
(static) isMainModule(callerModuleUrl) → {boolean}
- Description:
Determines whether the calling module is the entry point (directly executed by Node.js).
This is useful for scripts that can either be run directly via
nodeor imported by other modules. By checkingisMainModule(import.meta.url), you can conditionally execute code only when the file is the entry point.
- Source:
Example
import { isMainModule } from "nsuite";
if (isMainModule(import.meta.url)) {
// This block runs only when this file is executed directly
myFunction();
}
Parameters:
| Name | Type | Description |
|---|---|---|
callerModuleUrl |
string | The |
Returns:
true if the calling module is the Node.js entry point, false otherwise.
- Type
- boolean