Node.jsexpression3

我想把下面的一个帮手,但我得到,并在我的app.js需要它。 我目前的错误是没有定义的应用程序。 我对node.js是新手,所以如果这是一个容易的人不要对我很难。

app.locals.use({flashMessages: function(req, res) { var html = "" , flash = req.flash(); ['error', 'info'].forEach(function(type) { if(flash[type]) { flash[type].forEach(function(message) { html += "<div class='alert " + type + "'>" + message + "</div>"; }); } }); return html; }}); 

您应该将其转换为接受应用程序参数的函数,也可以将应用程序放入GLOBAL中。 请参阅node.js全局variables?