Reputation: 39
I wrote this route to find user every time I'm entering wrong user I didn't getting res.json() msg
app.post('/authenticate', function(req, res){
user.findOne({email : req.body.username}, function(err, user){
if(err){
res.json('user not found'); //not getting this
}else{
console.log(user); //probably this ran, cuz getting null at cmd
}
})
})
Upvotes: 1
Views: 160
Reputation: 12945
When username doesn't match with any of document , it returns empty user json . Error err object is null so res.json is unreachable , so you have to handle this by
app.post('/authenticate', function(req, res){
user.findOne({email : req.body.username}, function(err, user){
if(err){
throw err;
}else{
if(user){
console.log(user); //probably this ran, cuz getting null at cmd
}else{
console.log("User Not Found");
}
}
})
})
Upvotes: 1