Javascript 在节点js路由中使用外部函数
我试图在路由中使用一个外部函数,它将更改应用于我的ejs视图 以下是我的项目结构:Javascript 在节点js路由中使用外部函数,javascript,node.js,visual-studio,express,ejs,Javascript,Node.js,Visual Studio,Express,Ejs,我试图在路由中使用一个外部函数,它将更改应用于我的ejs视图 以下是我的项目结构: Project functions Evening.js Morning.js MyFunc.js routes about.js index.js users.js views about.ejs index.ejs app.js 此外,我还有我的My
Project
functions
Evening.js
Morning.js
MyFunc.js
routes
about.js
index.js
users.js
views
about.ejs
index.ejs
app.js
此外,我还有我的MyFunc.js:
var morning = require('./Morning');
var evening = require('./Evening');
module.exports = {
GetMorningMessage: function () { console.log(morning); },
GetEveningMessage: function () { console.log(evening); }
};
我知道我可以在我的app.js中使用app.get()
来设置将某些更改应用于我的视图所需的所有参数,但我想知道我是否可以在app.js中使用app.use()
,并调用路由中的外部函数,如router.get()
例如,像这样的(在index.js中):
var morning = welcome.GetMorningMessage();
router.get('/', function (req, res) {
res.render('index', {
title: 'The index page!',
h1: 'The h1',
username: username,
currentDate: currentDate,
MyVar: morning
});
});
var-morning=require('./morning')
您的morning
变量包含什么?GetMorningMessage
,不返回任何内容,它只是在早晨注销。。