【发布时间】:2017-11-10 15:46:58
【问题描述】:
我是 nodeJs 的新手,并试图理解为什么在这个文件--app.js--函数 main() 永远不会被执行。
如果我在函数之前添加一个 console.log 语句,它会被执行,但函数内部没有任何内容被执行。
我已经使用了调试器,果然,该功能被完全跳过了。
为什么会这样?是否有一些我忽略的节点组件?
'use strict';
const sendEmail = require('./send-email');
module.exports = main;
//console.log("This gets executed");
//this function never gets executed!
function main()
{
debugger
...some functionality...
}
【问题讨论】:
-
你如何调用你的函数?
-
如果
app.js是您的入口脚本,Node.js 不会使用定义main函数的模式,该函数会在执行时自动调用。整个入口脚本,从第 1 行第 1 个字符开始,是启动应用程序行为/逻辑的“主”代码。
标签: javascript node.js debugging execution