-1

I am using mongoose, express.js and angular.js

My Problem is that i am getting an empty req.body.

I would appreciate any help. Thank you.

$http({
        method:'DELETE',
        url:'/api/delete',
        data:$scope.selected._id
    }).success(function (data) {
        alert("worked");
    }).error(function(e){
        alert("not");
    });
});


app.delete('/api/delete', function(req,res, next){

console.log(req.body);
Model.remove({"_id":req.body},function(err){
    if(err){
        res.send(err);
    }else{
        res.json("Worked");
    }

});
user2355793
  • 87
  • 2
  • 12
  • 1
    Possible duplicate of [angular $resource delete won't send body to express.js server](http://stackoverflow.com/questions/22186671/angular-resource-delete-wont-send-body-to-express-js-server) – Ben Fortune Mar 10 '16 at 15:42

1 Answers1

-1

Are you using body-parser middleware within your express app? By default the request object will not have a body key.

Here is how you could add it to your app.

var bodyParser = require('body-parser')


// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// parse application/json
app.use(bodyParser.json());
user2263572
  • 5,435
  • 5
  • 35
  • 57