title: POST data from angular to node not working
body: <p>I am using angular to send data to node server but it is not working. I am not able to see my post data(input values in form) in my node post method. I need to get that data save in mongoDb but I don't know why I can't see the POST values sent by the front-end.</p>
  
  <p>I am not able to see my form data in node via console.log(). Sometimes it returns {} and sometimes POST is recognised as OPTIONS req by 'morgan' debugger when I use </p>
  
  <pre><code>console.log(req.body.fname);
  </code></pre>
  
  <p>My Html :</p>
  
  <pre><code>    &lt;body ng-app="app" ng-controller="MyController"&gt;
      &lt;div id="login-page" class="row"&gt;
          &lt;div class="col s12 z-depth-6 card-panel"&gt;
              &lt;form ng-submit="postData();"&gt;
                  &lt;div class="row" style="height: 90px;background-color:#00BFA5;margin: -12px -12px 15px -12px"&gt;
                      &lt;h3 class="center-align"&gt;Register&lt;/h3&gt;
                  &lt;/div&gt;
                  &lt;div class="row margin"&gt;
                      &lt;div class="input-field col s12"&gt;
                          &lt;i class="mdi-social-person prefix"&gt;&lt;/i&gt;
                          &lt;input id="fname" name="fname" ng-model="formData.fname" type="text" class="validate"&gt;
                          &lt;label for="fname" class="center-align"&gt;First Name&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div class="row margin"&gt;
                      &lt;div class="input-field col s12"&gt;
                          &lt;i class="mdi-social-person-outline prefix"&gt;&lt;/i&gt;
                          &lt;input id="lname" name="lname" ng-model="formData.lname" type="text" class="validate"&gt;
                          &lt;label for="lname" class="center-align"&gt;Last Name&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row margin"&gt;
                      &lt;div class="input-field col s12"&gt;
                          &lt;i class="mdi-action-account-circle prefix"&gt;&lt;/i&gt;
                          &lt;input id="username" type="text" name="formData.username" ng-model="username" class="validate"&gt;
                          &lt;label for="username" class="center-align"&gt;Username&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row margin"&gt;
                      &lt;div class="input-field col s12"&gt;
                          &lt;i class="mdi-communication-email prefix"&gt;&lt;/i&gt;
                          &lt;input id="email" type="email" class="validate" name="email" ng-model="formData.email"&gt;
                          &lt;label for="email" class="center-align"&gt;Email&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row margin"&gt;
                      &lt;div class="input-field col s12"&gt;
                          &lt;i class="mdi-action-lock prefix"&gt;&lt;/i&gt;
                          &lt;input id="password" type="password" class="validate" name="password" ng-model="formData.password"&gt;
                          &lt;label for="password"&gt;Password&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row margin"&gt;
                      &lt;div class="input-field col s12"&gt;
                          &lt;i class="mdi-action-lock-outline prefix"&gt;&lt;/i&gt;
                          &lt;input id="password-again" type="password" name="pass_again"&gt;
                          &lt;label for="password-again"&gt;Re-type password&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div class="row"&gt;
                      &lt;button class="btn waves-effect waves-light validate col s6 push-s3"
                              style="margin-top: 15px;"
                              type="submit"&gt;Submit
                          &lt;i class="material-icons right"&gt;send&lt;/i&gt;
                      &lt;/button&gt;
                      &lt;div class="input-field col s12"&gt;
                          &lt;p class="margin center medium-small sign-up"&gt;Already have an account? &lt;a
                                  href="login.html"&gt;Login&lt;/a&gt;&lt;/p&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
              {{ServerResponse}}
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;script type="text/javascript" src="js/angular_min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="js/jquery-1.11.3.min.js"&gt;&lt;/script&gt;
      &lt;script src="js/materialize.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          angular.module('app', []).controller('MyController', function ($scope, $http) {
              $scope.postData = function () {
                  $http.post('http://localhost:3000/api/post', $scope.formData)
                          .success(function (data) {
                              $scope.ServerResponse = data;
                          }).error(function (data) {
                      $scope.ServerResponse = data;
                  })
              }
          })
      &lt;/script&gt;
      &lt;/body&gt;
  </code></pre>
  
  <p>My node code:</p>
  
  <pre><code>    require('rootpath')();
      var express = require('express');
      var app = express();
      var bodyParser = require('body-parser');
      var morgan = require('morgan');
      var mongoose = require('mongoose');
  
      var jwt = require('jsonwebtoken');
      var config = require('config.json');
      app.set('view engine', 'ejs');
      app.set('views', __dirname + '/views');
  
      var port = process.env.PORT || 3000;
      mongoose.connect(config.connectionString);
      app.set('superSecret', config.secret);
      app.use(bodyParser.urlencoded({extended: true}));
      app.use(bodyParser.json());
      app.use(morgan('dev'));
      app.post('/api/post', function (req, res) {
          console.log(req.body.fname);
      });
      app.listen(port);
      console.log('Magic happens at http://localhost:' + port);
  </code></pre>
  
  <p>Thanks.</p>