如何检测是否使用SH:node path-to-file或JS:调用了Node.JS文件require('path-to-file')?
node path-to-file
require('path-to-file')
if (require.main === module) { console.log(‘called directly’); } else { console.log(‘required as a module’); }
请在此处查看有关此文档的文档:https : //nodejs.org/docs/latest/api/modules.html#modules_accessing_the_main_module