Search code examples
javascriptnode.jsexpressflashpassport.js

Stuck with req.flash is not a function error


followning is my app.js code and wherever i have put app.use(req.flash()); it give me this error i have tried different stacks for it buts its not working

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

at this stage if i move routers down it give me some error of status code:1

app.use('/', index);
app.use(session({
  secret : 'abc',
  saveUninitialized : true,
  resave : true
}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());

Solution

  • app.use(function(req, res, next) {
    res.locals.sucess_msg = req.flash('sucess_msg');
    res.locals.error_msg = req.flash('error_msg');
    res.locals.error = req.flash('error');
    next();});