title: How do I make a patch request in nodeJs/Express using Pug as a template engine
body: <p>PleaseI am working on a blog site with nodejs/express, mongoDB and using Pug . I am currently trying to send comments to my post data using a patch request from Pug and having some issues. Below is the details.</p>
  
  <p>I have a server folder in root directory which has a <strong>blogPost.js</strong> file. This blogPost.js file contains the code below </p>
  
  <pre><code>...
  router.patch('/comment/:postId', async (req, res) =&gt; {
      try{
      const updatedPostComment = await BlogPost.updateOne({ _id: req.params.postId }, 
          {
              $push: {
                  comment: [{
                      author: req.body.comment.author,
                      text: req.body.comment.text   
              }]}      
              });
          res.json(updatedPostComment);
              }catch (err) {
                  res.json({ message: err });
      }
  });
  ...
  </code></pre>
  
  <p>This code works fine when I test it with postman. I am able to make a patch request from postman to update the comment array in my data for a specific post in mongoDb based on the Id of the post.</p>
  
  <p>I also have an <strong>index.js</strong> file in the root folder which has the code below,</p>
  
  <pre><code>...
  //Set Pug
  app.set('view engine', 'pug');
  
  //Pug Routes/Request
  app.get('/', async (req, res) =&gt; {
      const query = await axios.get('http://localhost:1800/post');
      res.render('index', { posts: query.data });
    });
  ...
  app.patch('/comment/:id', async (req, res) =&gt; {
      const query = await axios.patch('http://localhost:1800/post/comment/' + req.params.id);
      res.render('comment', { 
        id: req.params.id
       });
    });
  
  // Connect to DB
  mongoose.connect( 
      process.env.DB_CONNECTION, 
      {  useNewUrlParser: true ,
         useUnifiedTopology: true, 
      },
      () =&gt; console.log('Connected to DB')
  );
  
  const port = process.env.PORT || 1800;
  app.listen(port, () =&gt; console.log(`server started on port ${port}`));
  </code></pre>
  
  <p>and finally, I have <strong>index.pug</strong> file in my views folder which has a form in the code below</p>
  
  <pre><code>extends layout
  block content
      br
      - const post = posts[0]
  
          div
              form(action=`http://localhost:1800/post/comment/${post._id}` method="patch" class="was-validated shadow font-weight-bold")
                  .form-group.mx-3
                      label(for="" class="text-uppercase") Author
                      input(type="text" name="author" id="" class="form-control" required)
                  .form-group.mx-3
                      label(for="" class="text-uppercase") Comment
                      input(type="text" name="text" id="" class="form-control" required)
                  .text-center
                      input(type="submit" value="Send Post" class="btn btn-primary mt-4 mb-5")
  </code></pre>
  
  <p>When I try to send the patch request from the form, it does not work as it worked from the postman.
  This is the error i have in my console and url when send text to the form</p>
  
  <p><strong>get <a href="http://localhost:1800/post/comment/5ebcf79271217d299c6d2f1eauthor=Kwabena+Attakora+Frimpong&amp;text=thank+you+God" rel="nofollow noreferrer">http://localhost:1800/post/comment/5ebcf79271217d299c6d2f1eauthor=Kwabena+Attakora+Frimpong&amp;text=thank+you+God</a> 404 error</strong></p>
  
  <p>Please what am I missing. Is it from the form action or am missing something in the indexjs file. Pleae I am stack and I need help. thank you for your support.</p>