title: Passing an error from POST route to ejs template
body: <p>So I've been trying to figure out for hours, how to pass an error from a POST route in Express to an EJS template. I'm building a blog app and I want to prevent the redirect to the root route and instead display an error if the title input or text area are empty. Can this be done server-side or do I have to track the inputs on the client-side?</p>
  <p>Here is my Compose template:</p>
  <pre><code> &lt;form action=&quot;/compose&quot; method=&quot;POST&quot;&gt;
      &lt;div class=&quot;form-group&quot;&gt;
        &lt;label for=&quot;postTitle&quot;&gt;Title&lt;/label&gt;
        &lt;input type=&quot;text&quot; name=&quot;postTitle&quot; class=&quot;form-control&quot; id=&quot;postTitle&quot; autocomplete=&quot;off&quot;&gt;
        &lt;label for=&quot;postBody&quot;&gt;Post&lt;/label&gt;
        &lt;textarea name=&quot;postBody&quot; class=&quot;form-control&quot; autocomplete=&quot;off&quot; rows=&quot;8&quot;&gt;&lt;/textarea&gt;
      &lt;/div&gt;
        &lt;button type=&quot;submit&quot; name=&quot;button&quot; class=&quot;btn btn-primary&quot;&gt;Publish&lt;/button&gt;
    &lt;/form&gt;
  </code></pre>
  <p>Here's my GET and POST routes:</p>
  <pre><code>  compose_get: (req, res) =&gt; res.render(&quot;compose&quot;),
  
    compose_post: (req, res) =&gt; {
      const postTitle = req.body.postTitle;
      const postBody = req.body.postBody;
  
      let postDate = new Date();
  
      const post = new Posts({
        date: postDate,
        title: postTitle,
        content: postBody
      });
  
      post.save(err =&gt; {
        if (!err) {
          res.redirect(&quot;/&quot;);
        }
      });
    }
  </code></pre>