require.main
新增于: v0.1.17
Module 对象代表 Node.js 进程启动时加载的入口脚本,如果程序的入口点不是 CommonJS 模块,则为 undefined。参见 "访问主模块"。
\The Module object representing the entry script loaded when the Node.js
process launched, or undefined if the entry point of the program is not a
CommonJS module.
See "Accessing the main module".
在 entry.js 脚本中:
\In entry.js script:
console.log(require.main); node entry.js Module {
id: '.',
path: '/absolute/path/to',
exports: {},
filename: '/absolute/path/to/entry.js',
loaded: false,
children: [],
paths:
[ '/absolute/path/to/node_modules',
'/absolute/path/node_modules',
'/absolute/node_modules',
'/node_modules' ] }