title: Unable to parse POST req with body-parser installed
body: <p>I am working on a small server app to allow clients to create users. I can't parse the req.body. I tried to read everywhere on Internet but not solution available for me.</p>
  
  <p>I have 2 files on the root of my projet.
  - server.js for api config, and
  - app.js for app config</p>
  
  <pre><code>// app.js
  const express = require('express');
  const bodyParser = require('body-parser');
  const router = require('./routes/index.routes');
  
  const app = express();
  
  // Parse incoming requests data
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());
  app.use(router);
  </code></pre>
  
  <p>My routes are in routes/index.routes.js</p>
  
  <pre><code>const express = require('express');
  const QuickCreditCtrl = require('../controller/controller');
  
  const router = express.Router();
  
  const baseUrl = '/api/v1';
  
  router.post(`${baseUrl}/auth/signup`, QuickCreditCtrl.createUser);
  //router.post(`${baseUrl}/auth/signin`, QuickCreditCtrl.loginUser);
  
  module.exports = router;
  
  </code></pre>
  
  <p>And controllers on controller/controller.js</p>
  
  <pre><code>const user = require('../data/users');
  
  class QuickCreditsCtrl {
      createUser(req, res) {
          console.log(JSON.stringify(req.body));
          if (!req.body.name) {
              return res.status(404).send({
                  status: '404',
                  message: 'name is required',
              });
          } else if(!req.body.email) {
              return res.status(404).send({
                  status: 404,
                  message: 'email is required'
              });
          }
          const userNew = {
          id: user.length + 1,
          email: req.body.email,
          name: req.body.name,
          password: 'user123',
          };
          user.push(userNew);
          return res.status(200).send({
              status: 200,
              //message: 'New user added successfully',
              userNew,
              //data: userNew
          });
      }
  
  }
  
  const QuickCreditCtrl = new QuickCreditsCtrl();
  
  //export default QuickCreditCtrl;
  module.exports = QuickCreditCtrl;
  
  </code></pre>
  
  <p>When I use Postman or curl everything is OK except that I can't access the req.body. I can't figure out why whereas I am using body-parser.</p>
  
  <p>Is there something wrong on my code?</p>
  
  <h2>Edit</h2>
  
  <p>I am trying to simplify things but I can't still access the req.body. I've read too much but can't find solution to my problem. In the file below I try to do everything in the app.js file but in vain:</p>
  
  <pre><code>const express = require('express');
  const bodyParser = require('body-parser');
  const db = require('./data/users')
  
  const app = express();
  
  // Parse incoming requests data
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  
  app.post('/api/v1/auth/signup', (req, res) =&gt; {
    const data = {
          id: db.length + 1,
          email: req.body.email,
          firstN: req.body.firstN,
          lastN: req.body.lastN,
          password: 'Patie123',
        };
        db.push(data);
        return res.status(200).send({
          status: 200,
          message: 'User created successfully',
          data,
        });
        console.log(data);
  });
  
  module.exports = app;
  </code></pre>
  
  <p>What is really wrong with my code? Or how do you access req.body?</p>