connect-flash middleware not working

im trying to get connect-flash working in my express3 application.

I installed successfully the package:

$ npm install connect-flash

I included it:

var flash = require('connect-flash');

Setted up the middleware:

app.use(function(req, res, next) {
    res.locals.message = req.flash();
    next();
  });
app.use(flash());

And used it:

app.get('/admin', function(req, res) {   
    if(loggedIn === true) {      
      res.redirect('/admin/books');
    }
    else {      
      res.render('login', {message: req.flash('error') });
    }    
  });
  app.post('/admin', function(req, res) {    
    if((adminAccount.username === getCrypted(req.body.username)) && 
      (adminAccount.password === getCrypted(req.body.password))) {

      loggedIn = true;
      res.redirect('/admin/books');
    }
    else {
      req.flash('error', 'Woops, looks like that username and password are incorrect.');
      res.redirect('/admin');
    }
  });

However I get: TypeError: Object #<IncomingMessage> has no method 'flash'. I followed the instructions on its github page. What am I missing?

Reverse the ordering:

app.use(flash());

app.use(function(req, res, next) {
  res.locals.message = req.flash();
  next();
});