I have my angularjs code which tries to send a post request as follows
var req = {
method: 'POST',
url: 'http://localhost:3300/addInventoryItem',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
item_name : item.itemName
}
};
$http(req).then(function(response){...});
I have my nodejs express code to have this
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.post("/addInventoryItem", function(req, res) {
console.log(req.body);
});
I always get the request in my node as
{ '{"item_name":"sweetB"}': '' }
Why is the req.body
have the key as the entire form data as key? How can I solve this?
EDIT I am using express with body-parser module
Thanks for your help