I'm sening an id to a module checking if the message hjas been sent or not. After it has not been sent I 'm sending the message:
var l = require('./control.js')
sonuc = l.check(id);
And my module is
exports.check = function(id, callback){
try{
client.query("SELECT req FROM messages where req = 0 and id = "+id,
function (err, results, fields) {
if (results.length > 0){
callback(false);
}else{
callback(true);
}
});
callback();
}catch(err){
console.log(err);
}
}
But it's failing and returning undefined variable.
returning from an asynchronous function doesn't mean anything; the whole point of using a callback is so you can get the value at a later date:
var l = require('./control.js')
l.check(id, function(sonuc) {
// Here the value of sonuc is set.
});
You may be interested in this screencast, which goes over the topic in a bit more detail.