title: Node.js/Express post route failing
body: <p>Trying out Node.js for the first time. My POST route is failing with &quot;Cannot POST /admin/add-product.html&quot;. GET request is being served fine from the same route.  I have had a look around here. Several answers to similar issues but nothing is helping. Here is my code:</p>
  <p>./index.js</p>
  <pre><code>const path = require('path');
  
  const express = require('express');
  const bodyParser = require('body-parser');
  
  const app = express();
  
  const adminRoutes = require('./src/routes/admin');
  const shopRoutes = require('./src/routes/shop');
  
  app.use(bodyParser.urlencoded({ extended: false }));
  
  app.use('/admin', adminRoutes);
  app.use(shopRoutes);
  
  app.listen(3000);`
  </code></pre>
  <p>./src/routes/admin.js</p>
  <pre><code>const path = require('path');
  
  const express = require('express');
  
  const router = express.Router();
  
  // served on /admin/add-product GET route
  router.get('/add-product', (req, res, next) =&gt; {
    res.sendFile(path.join(__dirname, '../', 'views', 'add-product.html'));
  });
  
  // served on /admin/add-product POST route
  router.post('/add-product', (req, res, next) =&gt; {
    console.log(req.body);
    res.redirect('/');
    // res.send('&lt;h1&gt;product saved&lt;/h1&gt;');
  });
  
  module.exports = router;
  </code></pre>
  <p>./src/views/add-product.html</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
    &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot; /&gt;
      &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot; /&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;
      &lt;title&gt;Add Product&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;header&gt;
        &lt;nav&gt;
          &lt;ul&gt;
            &lt;li&gt;&lt;a href=&quot;/&quot;&gt;Shop&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;add-product&quot;&gt;Add Product&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
        &lt;/nav&gt;
      &lt;/header&gt;
      &lt;main&gt;
        &lt;form action=&quot;/admin/add-product.html&quot; method=&quot;POST&quot;&gt;
          &lt;input type=&quot;text&quot; name=&quot;title&quot; /&gt;&lt;button type=&quot;submit&quot;&gt;
            Add Product
          &lt;/button&gt;
        &lt;/form&gt;
      &lt;/main&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Thank you!!!</p>