I have written following code to read JSON Object from request. The issue is that it prints the whole object in 1 key and set empty value of it.
This is what i am doing.
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
/**
*
* Add User
*/
app.post('/addUser', function (req, res) {
console.log(req.body);
})
I am passing following object to this route.
{"id": 1, "name": "Taha" }
and getting this as output.
{ '{"id": 1,\n"name": "Taha"\n}': '' }