detect whether ES Module is run from command line in Node
问题 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 equivalent way to detect whether a script is being run from the command line when using ES Modules in Node (with the --experimental-modules flag)? 回答1: 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