How can I detect if server.js is included or directly ran, so I can export.server or just server.listen(port) ?
Thanks
To check for all locally installed packages and their dependencies, navigate to the project folder in your terminal and run the npm list command. You can also check if a specific package is installed locally or not using the npm list command followed by package name.
Which function is used to include modules in Node Js. require(); 8.
To list the modules installed locally in a project, enter the project directory and execute the npm list command, as shown in the example below.
From http://nodejs.org/docs/latest/api/modules.html#accessing_the_main_module
When a file is run directly from Node, require.main is set to its module. That means that you can determine whether a file has been run directly by testing
require.main === module
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With