detect whether ES Module is run from command line in Node

后端 未结 1 1683
谎友^
谎友^ 2020-11-29 13:40

When using CommonJS modules in Node, you can detect whether a script is being run from the command line using require.main === module.

What is an equiva

相关标签:
1条回答
  • 2020-11-29 13:53

    There is none - yet (it's still experimental!). Although the prevailing opinion is that such a check is a bad practice anyway and you should just provide separate scripts for the library and the executable, there is an idea to provide a boolean import.meta.main property for this purpose.

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