2

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.

enter image description here

But if I submit data using raw json format, I am getting req.body data and everything is working nicely.

enter image description here

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.

Community
  • 1
  • 1
Muhaimenul Islam
  • 747
  • 1
  • 7
  • 22

0 Answers0