NOTE:本文持续更新
CommonJS Module
用require.main判断是否用命令行运行程序
if (require.main === module) {
// this module was run directly from the command line as in node xxx.js
} else {
// this module was not run directly from the command line and probably loaded by something else
}
https://stackoverflow.com/questions/45136831/node-js-require-main-module
这篇博客介绍了如何在 Node.js 中使用 `require.main === module` 来判断当前模块是否是通过命令行直接运行的。如果 `require.main` 等于 `module`,那么该模块就是直接从命令行启动的;否则,它可能是被其他模块加载的。

被折叠的 条评论
为什么被折叠?



