Search code examples
node.jsexpressbody-parser

BodyParser is giving an empty object


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);
});

Solution

  • With postman, ensure you have one of these two Content-Type headers set:

    If this is not the issue, please do edit your question to include the cURL version of your request, for more helpful answers.