How to have a CommonJS module execute its main() (as in Python)?

后端 未结 1 939
天涯浪人
天涯浪人 2021-01-15 04:14

I wonder if a method exists that would run a predefined function in a CommonJS module (as those used in Node.js). I wrote a couple of node modules that act as services/serve

相关标签:
1条回答
  • 2021-01-15 04:55
    if (require.main === module) {
        console.log("running standalone");
    }
    

    accessing the main module

    0 讨论(0)
提交回复
热议问题