0

In express req.body is {} at the time of post method

I am creating a nodejs API in which I am using express, mongoose, body parser. When I hit on end point /ap/register. I am not receiving response because of empty req.body. Controller file const userModel = require('../models/userModel') module.exports = { "registerUser": (req,res)=>{ if(!req.body){ res.status(400).send({ "message": "User Detail Cannot be empty" }) } else{ const user = new userModel({ name : req.body.name, email : req.body.email, password : req.body.password }) user.save().then(data=>{ res.status(200).send(data) }).catch(err=>{ res.status(500).send({ "message": err.message || "Something went wrong" }) }) } }, "login":(req,res)=>{ res.send({ "message":"This is an register method" }) }

9/4/2019 4:59:10 PM

Dheeraj Sharma

0 Answers

New Answer