title: Nodejs Flash messages only loads after the page is refreshed (connect-flash)
body: <p>I'm getting stuck with connect-flash , all flash messages doesn't load on the page unless I refresh for a couple of times I'm not sure why.</p>
  
  <p>I created a small project just to test connect-flash and it's the same result, please check the code below:</p>
  
  <p>App.js code: </p>
  
  <pre><code>const express = require('express');
  const path = require('path');
  const favicon = require('serve-favicon');
  const logger = require('morgan');
  const cookieParser = require('cookie-parser');
  const bodyParser = require('body-parser');
  const session = require('express-session');
  const flash = require('connect-flash');
  const app = express();
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'hbs');
  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(session({
   secret: 'keyboard cat',
   resave: false,
   saveUninitialized: true
  }));
  //using flash
  app.use(flash());
  app.use(function(req, res, next){
   res.locals.success = req.flash('success');
   res.locals.error = req.flash('error');
   next();
  });
  //flash route
  app.get('/flash', (req, res) =&gt;{
   req.flash("success", "CONNECT FLASH TEST");
   res.render('flash');
  });
  const port = process.env.PORT || 5000;
  app.listen(port, () =&gt;{
   console.log(`App has started on port ${port}`);
  })
  </code></pre>
  
  <p>Here's the code for the flash.hbs page to render the flash message: </p>
  
  <pre><code>&lt;h1&gt;Flash page&lt;/h1&gt;
  {‌{#if success}}
  &lt;h2&gt;{‌{success}}&lt;/h2&gt;
  {‌{/if}}
  </code></pre>
  
  <p>Thanks so much in advanced, any help would be highly appreciated guys.</p>