Reputation: 3083
I want to put the fallowing in a helper but i get and require it in my app.js. My current error is app is not defined. I am new to node.js so if this is a easy one dont be to hard on me.
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; }});
Upvotes: 2
Views: 760
Reputation: 35106
You should either convert this to a function that accepts an app parameter, or you could put app into GLOBAL. See node.js global variables?
Upvotes: 2