in my self-defined module I have this method which will query the db and find if the username exists in my db. I want some values to be returned so in the upper level I will know the query result.
var findUserbyUsername=function(username)
{
db.users.find({email:username},function(err,result)
{
if(err|!username) {console.log('username not found'); return 0;}
else return 1;
}
);
}
module.exports.findUser=findUserbyUsername;
in app.js I will call the above method like this
var lt=dbutil.findUser('xxxx@gmail.com');
but unfortunately I got undefined….
Can anyone help me workaround this ? Or any other suggestions ?
This is an asynchronous code, of course it’s not going to return anything. You might want the following:
app.js:
module: