title: express receiving empty request body when receiving from angular 4 app
body: <p>The body of the request being sent is empty according to req.body in my express route.</p>
  
  <p>My main node file is as follows - </p>
  
  <pre><code>var express = require('express');
  var bluebird = require('bluebird')
  const bodyParser = require('body-parser');
  const cors = require('cors');
  
  /*initializations*/
  global.mongoose = require('mongoose');
  mongoose.Promise = bluebird
  global.app = express();
  global.config = require('./config/config');
  global.jwt = require('jsonwebtoken');
  app.use(bodyParser.json({ type: 'application/json' }))
  app.use(bodyParser.urlencoded({ extended: true }));//accept strings, arrays   and any other type as values
  app.disable('x-powered-by');
  
  require('./routes/auth.routes');
  
  //DB connection
  app.listen(config.port, function(){
   console.log("Express started on " +config.base_url +' in '+config.env +' environment. Press Ctrl + C to terminate');
   mongoose.connect(config.db.uri, config.db.options)
   .then(()=&gt; { console.log(`Succesfully Connected to the Mongodb Database  at URL : `+config.db.uri)})
   .catch((error)=&gt; { console.log(error)})
  });
  </code></pre>
  
  <p>The auth.routes file has the signup route and this is where the req.body is empty but it does not hit the if statement that checks, but when i console.log(re.body), it gives me that - {} </p>
  
  <pre><code>app.post('/signup', function(req,res,next){
  
  if (!req.body||req.body=={}){
      return res.status(400).send("Bad Request")
  }
  
  var user = new User(req.body);
  
  user.password = bcrypt.hashSync(req.body.password, 10);
  
  User.create(user, function(err,new_user){
      if (err) {
          console.log('A Big Error');
          return res.status(500).send("There was a problem registering the user.")
      }
  
     //success code       
  
    })
  });
  </code></pre>
  
  <p>And the request from the angular 4 app is</p>
  
  <pre><code>signup(user:User):Observable&lt;boolean&gt;{
  
  return this.http.post(this.signup_url,JSON.stringify(user), 
    {
      headers: new HttpHeaders().set('Accept', "application/json;q=0.9,*/*;q=0.8").set('Content-Type', "x-www-form-encoded")
    })
    .map((response: Response) =&gt; {
        if(response){
          if(response.json() &amp;&amp; response.json().token&amp;&amp;response.json().user&amp;&amp;response.json().expires){
            this.setSession(response.json());
            return true;
          }
          else{
             return false;
          }  
        }
        else{
            return false;
        }
    });
  }
  </code></pre>
  
  <p>I am certain the Angular 4 app is sending the right data to the server and that its not empty - checked chromes network request body. </p>
  
  <p>I have tried the following links but none worked.</p>
  
  <p><a href="https://stackoverflow.com/questions/33489953/express-app-empty-request-body-with-custom-content-type-headers">Express app empty request body with custom content type headers</a></p>
  
  <p><a href="https://stackoverflow.com/questions/35897059/express-receiving-empty-object">Express receiving empty object</a></p>
  
  <p><a href="https://stackoverflow.com/questions/31396360/node-js-receiving-empty-body-when-submitting-form">Node.js: Receiving empty body when submitting form</a>.</p>
  
  <p>Also tried with postman and the result is the same - which means the problem is from the express server and not the client side.</p>