I am trying to return a value from module function and calling that function from different file, the function executes but return undefined
below is the code:
this is the module
teacherController={}
teacherController.getClassid = (req)=>{
Teacher.findOne({token:req.session.user})
.then((doc)=>{
var classid = doc.class
console.log(classid) // this logs the correct value
return doc;
}).catch((err)=>{
if(err) throw err;
})
}
module.exports = teacherController;
this is where i am calling the module function
student.get('/ranking',(req,res)=>{
var classid = teacher_con.getClassid(req);
console.log(classid); //this logs: undefined
});
thank you!