baniol
1/23/2014 - 10:43 AM

nodejs, express, flash messages, session

nodejs, express, flash messages, session

// http://stackoverflow.com/a/12254857
app.use(function(req, res, next) {
  var session = req.session;
  var messages = session.messages || (session.messages = []);
  req.flash = function(type, message) {
    messages.push([type, message]);
  };
  next();
});

// And in your view just do message = messages.pop().