I have created a simple login api, when I try texting the api in postman am getting the following error: Error: Can't set headers after they are sent to the client using node js
code that I have written is as follows:
//verify user
exports.verifyuser = (req, res) => {
User.findOne(req.body.email)
.then(user => {
if(!user) {
return res.status(404).send({
message:"no user with email id found"
});
}
res.send(user).then(function(res){
console.log('verify db res',res)
});
}).catch(err => {
if(err.kind === 'ObjectId') {
return res.status(404).send({
message: "Note not found with id "
});
}
return res.status(500).send({
message: "Error retrieving note with id "
});
});
};
Being new to express am unable to recognize where have I gone wrong, also am not getting the correct response like below :
here I have added abc3@gmail.com to the url but am getting response for aaaa@gmail.com
Kindly help me out here, any suggestions would be very helpful. Thank you in advance.