Skip to content
Flash message middleware for Connect and Express.
JavaScript Makefile
Branch: master
Clone or download
Pull request Compare This branch is 13 commits ahead, 1 commit behind jaredhanson:master.
jack2gs Merge pull request #1 from ultimate-tester/master
Updated to latest versions of mocha and chai, moved them to devDependencies
Latest commit 1f198d4 Mar 10, 2019

express-flash-2 Build Status

This middleware is based on connect-flash. I simplify it and rewite the tests with Mocha and Chai.

  • use res.flash() instead of req.flash();
  • res.flash() just for writing messages into the sesson;
  • all flash messages will be copied to res.locals.flash automatically.


$ npm install express-flash-2


Express 4.x

Flash messages are stored in the session. First, setup sessions as usual by enabling cookieParser and session middleware. Then, use flash middleware provided by express-flash-2.

var flash = require('express-flash-2');
var app = express();

  app.use(cookieParser('keyboard cat'));
    secret: 'keyboard cat',
    resave: true,
 // use  the flash middleware 

With the flash middleware in place, all requests will have a res.flash() function that can be used for flash messages.

app.get('/flash', function(req, res){
  // Set a flash message by passing the key, followed by the value, to res.flash().
  res.flash('info', 'Flash is back!')


For an example using express-flash-2 in an Express 4.x app, refer to the express4 example.


$ npm install  
$ make test



The MIT License

Copyright (c) 2012-2013 Jared Hanson <>

You can’t perform that action at this time.