I created express app and implemented flash message. Now when i get the flash messages from validation errors I am passing that messages to view. But when i try to get the messages in the view I am not able to see since app showing bunch of error lines. How can i display the error messages in the view based on Ejs view engine.
this is the error messages stored in req.flash('fail_msg')
[ { location: 'body',
param: 'email',
value: '',
msg: 'Email must be valid' },
{ location: 'body', param: 'phone', value: '', msg: 'Phone Number is required' }, { location: 'body', param: 'password', value: '', msg: 'Password is required' }, { location: 'body', param: 'agreeTerms', value: undefined, msg: 'Must agree term and condition' } ]
from My routes.js
function checkValidationResult(req, res, next) {
const result = validationResult(req);
if (result.isEmpty()) {
return next();
}
req.flash('fail_msg', result.array());
res.render('signup', { message: req.flash('fail_msg')});
}
And this is from ejs template
<%if('message'){%>
<% message.foreach(function(errors){ %>
<%=errors.msg%>
<% }) %>
<%}%>