Skip to content

Instantly share code, notes, and snippets.

@baniol
Created January 23, 2014 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baniol/8576533 to your computer and use it in GitHub Desktop.
Save baniol/8576533 to your computer and use it in GitHub Desktop.
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().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment