This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Closed 4 years ago.
I have a function that needs to get data from another function, but the second one is returning undefined and i don't know why.
function firstOne() {
const companys = companysList();
console.log(companys); // LOG UNDEFINED
};
.
function companysList(){
db.query('SELECT id FROM companys WHERE id > 0', (error, result) =>{
if (error) throw error;
console.log(JSON.stringify(result)); // LOG THE ids!
return result;
});
};
your companysList function doesn't return anything
Related
This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
How to return results of node's sqlite3 in a function?
(1 answer)
Closed 9 months ago.
function getAllUsers1 (){
var con = new sql.connect(config,(err)=>{
if(err){
console.log(err)
return err ;
}else{
console.log('1');
con.query("select * from WebMail_Send", function (err,data){
if(err){
console.log('invaled query..............');
return err ;
}else{
console.log(data);
return data;
}
})
}
});
}
router.get('/sql',(req,res,next)=>{
var getAllUsers = new getAllUsers1();
res.render('sql', { items: getAllUsers})
});
No Error but return nothing
I'm trying to get data from SQL DB and display it on the HBS page.
This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Closed 2 years ago.
I can't set value inside function. When I try to alert this value, I'm getting: undefined. How to take this value outside?
var startTrasyLat;
L.esri.Geocoding.geocode()
.text(document.getElementById('start').value)
.run(function (err, results, response) {
if (err) {
console.log(err);
return;
}
startTrasyLat = results['results'][0].latlng.lat;
});
alert(startTrasyLat);
Looks like you are trying to call an asynchronous function. You should put the alert inside said function, like this:
var startTrasyLat;
L.esri.Geocoding.geocode().text(document.getElementById('start').value).run(function (err, results, response) {
if (err) {
console.log(err);
return;
}
startTrasyLat = results['results'][0].latlng.lat;
alert(startTrasyLat);
});
This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Closed 4 years ago.
I have a problem with function check_mod.
function check_mod(user_id) {
db.each(`SELECT mode FROM users WHERE id = ` + user_id, [], (err, row) => {
if (err) {
throw err;
}
if(row.mode == 1)
{
return true;
}
});
}
if(check_mod('286927644405137408')) console.log("okay");
When i try to use this function, it returns "undefined" and i don't know why. I think that i should use async and await but i don't know how to use it.
I'm not sure but, I do notice that there is no semicolon at the end of the sql statement which could be causing the issue.
This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Closed 5 years ago.
as the title says I want to extract the variable status to be able to use it in another part of the code, is this possible?
RNAudioStreamer.status((err, status)=>{if(!err) console.log(status)})
Depending on the callback sync/async you can create a global variable or use promise.
let p = new Promise((resolve, reject) => {
RNAudioStreamer.status((err, status)=>{
if(!err) resolve(status); else reject(err);
})
});
// ...
p.then(status => {
// process status here
})
This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Closed 6 years ago.
Heres my code. I basicly want to return the 'body' var in my getFollows function. Setting vars obviously dont work, no idea how to get the variable. I can't change getUserFollowedChannels because its a package, and I need to return it to the function directly because of meteor server->client stuff.
'twitch.getFollows'() {
var followers = twitch.getUserFollowedChannels('atlatonin', function(err, body) {
if (err) {
return err;
} else {
console.log(body.follows[0].channel.display_name);
return body.follows[0].channel.display_name;
}
});
return followers;
},
You can pass a callback function as below:
'twitch.getFollows': function(done) {
twitch.getUserFollowedChannels('atlatonin', done);
}
And invoke the function as below:
twitch.getFollows(function(err, body) {
if (err) {
console.log(err);
//return err;
} else {
console.log(body.follows[0].channel.display_name);
//return body.follows[0].channel.display_name;
}
});