title: I am trying to display flash error message in express.js but req.flash('error') return empty array
body: <p>Inside authControllers.js, I redirect to /signup page along with an error flash message</p>
  
  <pre><code>    const err = validationResult(req);
      //find errors and convert to array
      const reqErrors = err.array();
      const errors = reqErrors.filter(e =&gt; e.msg !== 'Invalid value');
      let messages = [];
      //loops through erros and push them into messages array
      errors.forEach((error) =&gt; {
          messages.push(error.msg);
      });
      //check if we have error or not
     ** if (messages.length &gt; 0) {
          // Store error into flash , so we display it later
          req.flash('error', messages);
          res.redirect('/signup');
      }else{**
      //move further
      return next();
  }
  }
  </code></pre>
  
  <p>Inside userRoutes.js </p>
  
  <pre><code>userRouter.get('/',(req, res)=&gt;{
      console.log("hello from get route")
      console.log(req.flash())
      const errors = req.flash('error')
      console.log(errors.length)
      return res.render('signup',
      {
          title:"Chatting room Log in",
          messages: errors,
          // if error array &gt; 0 then we have an error need to display
          flag :errors.length &gt; 0 
      }
      );
  });
  </code></pre>
  
  <p>When i run the program , this is following console.log(req.flash()) output: </p>
  
  <p>{ error:
     [ 'Username is required and must be at least 5 characters.',
       'Email is invalid',
       'Password is required and must be at least 5 characters.' ] }</p>
  
  <p>However, the variable errors is an empty array, thus when I tried to output errors.length. I got 0. It supposed to give me length  3.</p>
  
  <p>Thanks for helping me! I am using connect-flash, passport.js , express.js.</p>