title: Why I don't get the req.body on one route ? Node JS
body: <p>Hello I have following problem with my Node JS Application:</p>
  
  <p>I want to do an authentication, but when I send a POST on that route I get "req.body.username = undefined". </p>
  
  <p>Its only on this route, other routes get the req.body without problems.</p>
  
  <p><a href="https://i.stack.imgur.com/I3cgF.png" rel="nofollow noreferrer">Debug: req.body undefined</a></p>
  
  <p>Packages:</p>
  
  <pre><code>var config = require('./config');
  var express = require('express');
  var app = express();
  
  var path = require("path");
  var bodyParser = require('body-parser');
  
  var bcrypt = require('bcrypt');
  var bcryptSaltRounds = 10;
  var jwt = require('jsonwebtoken');
  var cors = require('cors');
  
  app.set('superSecret', config.secret);
  
  app.use(bodyParser.urlencoded({ extended: false}));
  app.use(bodyParser.json());
  
  app.use(express.static('public'));
  app.options('*', cors());
  app.use(cors());
  
  app.use(express.static(path.join(__dirname, 'public')));
  </code></pre>
  
  <p>Here is the server route:</p>
  
  <pre><code>app.post('/auth', function (req, res, next) {
      var username = req.body.username;
      var password = req.body.password;
  
      User.findOne({
          where: { username: username}
      }).then(function (user) {
          if(user){
              bcrypt.compare(password, user.password).then(function (passcheck) {
                  if(passcheck){
                      var jwtUser = {
                          username: user.username,
                          firstname: user.firstname,
                          lastname: user.lastname,
                          acceslevel: "all"
                      };
  
                      //var mysuperSecretPwd = app.get('superSecret');
  
                      var token = jwt.sign(jwtUser, app.get('superSecret'), {
                          expiresIn: 1 // expires in 24 hours
                      });
  
                      res.json({
                          success: true,
                          message: 'Theres your key',
                          token: token
                      });
                  }else{
                      res.status(401).json({
                          success: false,
                          message: 'Authentification failed. Password or User wrong'
                      });
  
                  }
              });
          }else{
              res.status(401).json({
                  success: false,
                  message: 'Authentification failed'
              });
          }
      }).catch(next);
  });
  </code></pre>
  
  <p>Here is the ajax request:</p>
  
  <pre><code>$('#btnRegister').click(function () {
  
          var firstname = $('#txtFirstnameRegister').val();
          var lastname = $('#txtLastnameRegister').val();
          var username = $('#txtUsernameRegister').val();
          var password = $('#txtPasswordRegister').val();
  
          if(firstname == "" || lastname == "" || username == "" || password == ""){
              msg ="Please fill the fields.";
              showInfo(msg);
          }else{
              $('#msgInsteadOfAlert').hide(300);
  
              var userObject = {
                  firstname: firstname,
                  lastname: lastname,
                  username: username,
                  password: password
              };
  
              $.ajax({
                  method: post,
                  url: baseUrl + postUser,
                  data: userObject,
                  success: function () {
                      //TODO: CHECK RESPOND IF USER EXISTS
                      var msg = "User: " + username + " successfully added.";
                      showInfo(msg);
                  },
                  error: function (xhr, status, errorThrown) {
                      showErrorMessage(xhr, status, errorThrown);
                  }
              });
          }
      });
  </code></pre>
  
  <p>Thank you in advance.</p>