Express 3 #8

Closed
ryandesign opened this Issue Nov 22, 2012 · 9 comments

Comments

Projects
None yet
6 participants

The readme says "Express 2.x only". If this module is not compatible with or not needed with Express 3, could you add a section to the readme explaining what Express 3 users should do instead? This module is the first Google search result for "express flash messages" so users are likely to end up here.

Owner

tj commented Nov 22, 2012

just stuff whatever you want in the session

Right. As I understand it, express-messages uses the req.flash function which was removed in Express 3. So wouldn't express-messages still work with Express 3 if you use, say, the connect-flash module, which brings back the req.flash function? Alternately, as you say, you can just manually put some things in the session, and then manually get them out to display them again. I think information about this topic would make a great addition to the readme, for the benefit of other users.

I've tried to use it in conjunction with connect-flash:

app.use(flash());
  app.use(function (req, res, next) {
    res.locals.messages = require('express-messages');
    next();
  });

… to no avail. Oddly it just outputs index.js on the page.

Member

artcommacode commented Feb 22, 2013

@OliverJAsh That's because you're just returning a function there, you're looking for this:

app.use(flash());
app.use(function (req, res, next) {
  res.locals.messages = require('express-messages')(req, res);
  next();
});

Late I know, but it may be of use to some. Maybe the docs should be updated to reflect that with 'connect-flash' installed and the snippet above this will work fine with Express 3.

The solution above does not work in Express 4 (with connect-flash).

Member

artcommacode commented Jun 30, 2014

Seems as if I'm somehow subscribed to this issue ... anyway the below works fine for me in 4.x

app.use(require('connect-flash')());
app.use(function (req, res, next) {
  res.locals.messages = require('express-messages')(req, res);
  next();
});
Member

artcommacode commented Aug 1, 2014

Updated Readme.md to add usage instructions for Express 3+

Owner

Fishrock123 commented Aug 1, 2014

Landed in 84a895f

(@artcommacode Try to do this next time, haha)

Member

artcommacode commented Aug 1, 2014

Aha, will do! (Going to have to get a bit better at all the Github protocols than I am currently)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment