I am trying to show message in handlebar template using connect-flash package but message is not showing and its print count when i use {{loginMessage}} in login page. but not display message. here is my code
file..routes/index.js
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var flash = require('connect-flash');
const m_db = require('.././config/mongo_connection');
var Site = require('.././models/site');
var User = require('../models/user');
var bcrypt = require('bcrypt-nodejs');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
require('.././config/passport')(passport);
//routes start here
router.get('/login', function(req, res, next) {
res.render('passports/login.hbs', { message: req.flash('loginMessage','failed login') });
})
my app.js
app.use(require('express-session')({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false
}));
app.use(flash());
//
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));
// passport config
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
app.use('/users', users);
app.use('/api', api);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
Please help! Thanks!