title: req.body is undefined but body-parser but it is inslated
body: <p>i'm created an api and for this i'm using node.js. what is happening is following it whenever i make a post request even after passing the data correctly i am getting a validation error saying that the fields are empty. I did a check I noticed that req.body is undefined even installed and imported the body-parser
  I´m using body-parser: 1.19.0</p>
  <blockquote>
  <p>I already installed the body-parser and use.
  <a href="https://i.stack.imgur.com/SHce3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SHce3.png" alt="enter image description here" /></a></p>
  </blockquote>
  <pre><code>//Index.js
  const express = require(&quot;express&quot;);
  const app = express();
  const mongoose = require(&quot;mongoose&quot;);
  const dotenv = require(&quot;dotenv&quot;);
  const bodyParser = require(&quot;body-parser&quot;);
  //Import Router
  const authRoute = require(&quot;./routes/auth&quot;);
  
  dotenv.config();
  
  //Import Router Middlewares
  app.use(&quot;/api/user/&quot;, authRoute);
  
  //MiddleWare
  app.use(express.json());
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  
  
  mongoose
    .connect(process.env.DB_MONGO, {
      useNewUrlParser: true,
      useCreateIndex: true,
      useUnifiedTopology: true,
      useFindAndModify: false,
    })
    .then(() =&gt; {
      console.log(&quot;DB is connect&quot;);
    })
    .catch((err) =&gt; {
      console.log(err);
    });
  
  app.listen(8081, () =&gt;
    console.log(&quot;Servier is running  http://localhost:8081&quot;)
  );
  
  
  </code></pre>
  <p>This is the auth.js</p>
  <pre><code>const router = require(&quot;express&quot;).Router();
  const User = require(&quot;../model/User&quot;);
  
  //post method
  router.post(&quot;/register&quot;, async (req, res) =&gt; {
    const user = new User(req.body);
    console.log(req.body);
    user.save((err, data) =&gt; {
      if (err) {
        console.log(err);
        res.status(400).json({
          message: err,
        });
      } else {
        res.json({
          message: data,
          status: true,
        });
      }
    });
  });
  
  </code></pre>