I am trying to handle the post routers. I am getting req.body to be an empty object {} using postman please see my code... I know this has been asked quite a few times. but i couldn't find a solution for myself
const express = require('express');
const bodyParser = require('body-parser');
const app =express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.post('/register', (req, res)=>{
res.send(req.body);
});
With postman, ensure you have one of these two Content-Type
headers set:
application/json
:
You have to select the JSON
option from the dropdown
x-www-form-urlencoded
:
Since you've setup bodyParser to also support urlencoded queries
If this is not the issue, please do edit your question to include the cURL
version of your request, for more helpful answers.