0

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}': '' }

1 Answer 1

1

This is an issue on the client. Send the request with Content-Type: application/json in the header.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, Yes it was client issue, i didn't know about Content-Type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.