title: Passing message from backend to frontend
body: <p>I'm learning Node and EJS and need some help with my program.  I'm trying to get the data from Form and store in the database after validating it. During validation, I couldn't pass messages from backend to frontend. I'm not sure what I'm doing wrong.</p>
  <p>Backend Code :</p>
  <pre><code>let { agentname } = req.body;
  
  let errors = [];
  
  if (!agentname) {
    errors.push({ message: 'Please enter all Mandatory Fields' });
  }
  
  if (errors.length &gt; 0) {
    res.render('addagent', { errors });
  } else {
    pool.query(
      `SELECT * FROM agentinfo where agentname = $1`,
      [agentname],
      (err, results) =&gt; {
        if (err) {
          throw err;
        }
  
        console.log(results.rows);
  
        if (results.rows.length &gt;= 1) {
          errors.push({ message: 'Agent is already added. Please check again' });
          console.log(errors);
          res.render('addagent', { errors });
        }
      }
    );
  }
  </code></pre>
  <p>Front end:</p>
  <pre><code>&lt;section class=&quot;addsec&quot;&gt;
          &lt;div class=&quot;addagent&quot;&gt;
              &lt;h3&gt;Add Agent&lt;/h3&gt;
  
              &lt;ul&gt;               
                  &lt;% if(messages.error) { %&gt;
                  &lt;li&gt; Test Message &lt;/li&gt;
                  &lt;li&gt;&lt;%= messages.error %&gt;&lt;/li&gt;
                  &lt;% } %&gt;   
              &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/section&gt;
  
  </code></pre>
  <p>I try to print the message in the backend for validation and it is working fine in the backend but that messages are not seen on the front end.</p>
  <p>Please help to understand and fix this error</p>