title: Node - connect-flash not working
body: <p>I'm trying to display an error message with connect-flash but it seems not working. I've tried several ways to do this work but any of that worked. I gotta an web app with a similar config code and worked without any problem.</p>
  
  <p>here is my code:</p>
  
  <pre><code>const express = require('express')
  const moment = require('moment')
  const morgan = require('morgan')
  const bodyParser = require('body-parser')
  const db = require('./configs/db')
  const flash = require('connect-flash')
  const session = require('express-session')
  const cookieParser = require('cookie-parser')
  const app = express()
  
  app.set('view engine', 'ejs')
  app.set('views', 'views')
  app.set(db)
  app.use(bodyParser.urlencoded({extended:true}))
  app.use(bodyParser.json())
  app.use(morgan('dev'))
  app.use(cookieParser())
  app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true,
    cookie: { secure: true }
  }))
  app.use(flash());
  var sessionFlash = function(req, res, next) {
      res.locals.currentUser = req.user;
      res.locals.error = req.flash('error');
      res.locals.success = req.flash('success');
      next();
  
  }
  app.use(sessionFlash)
  
  
  
  
  app.get('/', function (req, res) {
    req.flash('error', 'Welcome');
    res.render('test', {
      title: 'Home',
    })
  });
  app.get('/addFlash', function (req, res) {
    req.flash('error', 'Flash Message Added');
    res.redirect('/');
  });
  </code></pre>
  
  <p>my EJS file:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;Test&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;%  if(error){ %&gt;
        &lt;div class=""&gt;
            &lt;h1&gt;&lt;%=error%&gt;&lt;/h1&gt;
        &lt;/div&gt;
      &lt;% } %&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>