Answer the question
In order to leave comments, you need to log in
How, using needle, sending a get request to return a value from the callback?
This code for sending a get request outputs a large object with a bunch of properties. I need to get what I returned with "return"
function findMaxID() {
var a = needle.get(URL, function(err, res){
if (err) throw err;
return 222;
});
console.log(a);
}
Answer the question
In order to leave comments, you need to log in
No way with return. Only callbacks/promises. This is an asynchronous request.
function findMaxID(cb) {
needle.get(URL, cb);
}
findMaxID(function(err, res){
if (err) throw err;
console.log(res); // -- данные доступны здесь
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question