我试图将我的应用程序与我的所有端点组织在一个文件中,并让这些端点在另一个文件中调用或执行代码。当我到达/
路由时,getindexPage
函数似乎根本不会被调用。我如何让程序执行home.js文件中的代码?谢谢。在多个文件中拆分代码后不调用函数
routes.js
var home = require('../routes/home.js');
module.exports = function (app) {
app.get('/', function (req, res) {
//no functional code
home.getIndexPage(); //Function call does not seem to work.
});
};
home.js
var ejs = require('ejs');
function getIndexPage (req, res) {
res.render('index.ejs');
res.console.log('got to function');
//No console message, no error.
};
module.exports.getIndexPage = function getIndexPage() { };
这个帖子里绝对没有问题...... – Salketer
你确定res.console.log? – Salketer