title: How angularJS ngResource pass variables to expressJS when doing http request operations to server?
body: <p>The issue here is, that i don't know how to pass some scope.data to expressjs when using ngResource, so then it can be used with express route to insert something to DB.</p>
  
  <p>ExpressJS REST</p>
  
  <pre><code> router.route('/Data')
      .get(function(req,res){
       var username = req.username;
       var collection = db.collection('users');
     collection.find({username:username}).toArray(function (err, doc){
         res.send(doc[0].pets);
     });
   })
     .post(function(req,res){
  
    !!//I would like to use some data from angular here//!!
      var name = req.body.name;
      var surname = req.bodysurname;
  
      collection.update({username: username}, {
          $push: {
              "details": {
                  name: name,
                  surname: surname
               }
           }
       }, function (err, result) {
           if (err) throw err;          
        });
      });
  </code></pre>
  
  <p>Angular Factory</p>
  
  <pre><code> (function() {
     'use strict';
  
   angular
       .module('App')
       .factory('Factory', function ($resource) {
           return $resource("/Data",{},
               { get:{ method:"GET",
                       cache:true,
                       isArray:true},
                save:{ method:"POST",
                       cache:true,
                       isArray:false
                 }});
          });
      })();
  </code></pre>
  
  <p>Controller.js</p>
  
  <p>This one works fine i use this function with ng-click()</p>
  
  <pre><code>$scope.load = function(){
          Factory.get(function (data){
             $scope.data = data;
          });
      };
  </code></pre>
  
  <p>With this one i have problem i have ng-models name and surname in view and i would like to send them to server so it can be used in REST route as req.body.name and req.body.surname.</p>
  
  <pre><code> $scope.AddData = function(){
          Factory.save()
          }); 
        };
  </code></pre>
  
  <p>I think that data should be passed here in this function AddData, however i haven't succeeded yet.</p>
  
  <p>So i tried as Jesus said but without results?</p>
  
  <pre><code> $scope.AddData = function(){
         Factory.save($scope.name) //I tried ({name:$scope.name}) too
       }); 
      };
  </code></pre>
  
  <p>After advices from Jesús Quintana I checked the details of method POST and it occurred that everything was all right on angular side i was missing extension of body parser on server Express side</p>
  
  <pre><code>  app.use(bodyParser.json())
  </code></pre>
  
  <p>So now it looks like this</p>
  
  <pre><code>  app.use(bodyParser.urlencoded({extended: true}));
    app.use(bodyParser.json());
  </code></pre>