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)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…