I am trying to develop a simple API using NodeJS and Express. But Whenever I am trying to make post request using PostMan and form-data, in req.body
I am getting undefined
, though I have used,
Accept: application/json
Content-Type: application/json
in Header
of my request.
But if I submit data using raw
json format, I am getting req.body
data and everything is working nicely.
In both cases, I am using npm body-parser
and tried using following codes and in my project's app.js,
app.use(bodyParser.urlencoded({ extended: false })) //tried both, true and false app.use(bodyParser.json())
app.use(bodyParser.json({ type: 'application/vnd.api+json' }))
app.use(bodyParser.raw({ type: 'text/xml' }));
I am not sure what is the problem, is the problem occuring from PostMan or there is problem in my code? Can anyone help e to explain the problem? Thanks.