I have a project that I need to use connect-flash, I am using view engine as ejs. Even I configure everything fine, in my opinion, connect-flash doesn't work. Could anybody please help me abput that?
Here how did I define the session, connect-flash and global variables:
app.use(cookieParser());
//Express session middleware
app.use(session({
secret: 'secret',
resave: true,
saveUninitialized: true
}));
//Connect flash middleware
app.use(flash());
//Global varibales
app.use(function (req, res, next) {
res.locals.error = req.flash('error');
res.locals.success = req.flash('success');
next();
});
Here is the export module get function:
module.exports.xxx_index_get = function(req, res) {
xxx.findOne({
id: 'xxx'
}).then(xxx=> {
req.flash('success', 'user succesfulyl registered')
res.render('xxx/xxx', {
xxx
});
});};
And here is the ejs file:
<% if(success.length > 0) { %><div class="alert alert-success">
<%= success %> </div><% } %>
I would be really thankful If somebody will help about that. Am I missing something?