router.post("/register",validator.validate("createUser"), function(req,res){
const register = User({
fullname:fullname,
contact:contact,
email:email,
password:bcrypt.hashSync(password, salt),
role:check_user.if_user_exists()
})
register.save()
}
The Below code is from check_user.js file
exports.if_user_exists= function(){
User.findOne({role:"Admin"},function(err,data){
if(data){
console.log("Inside User"+data)
return "User"
}else{
console.log("Inside Admin"+data)
return "Admin"
}
})
}
So the Problem i'm facing is, when the record is saved the role value is undefined, i think the problem is its not waiting for function to return value. Please help me out how to fetch the method value