I know this must be a really silly question, but I can’t figure out how to make it work. I’m learning node.js and mongojs, and this is my problem:
This is my server.js
server.get("/", function(request, response) {
if (user.whatever()) {
return response.send('true');
} else {
return response.send('false');
}
});
and this my user.js
exports.whatever = function(request, response) {
return db.tableName.findOne({
fieldName: null
}, function(error, record) {
if (record === null) {
return false;
} else {
return true;
}
});
};
the function returns “undefined”. I imagine that this is a problem of blocking code, but have no idea on how to convert it. Please help!
You should do that as following :
server.js
user.js