the function below is part of a node.js program that i am writing.
var getDataFromUrl = function(url) {
rest.get(url).on('complete',function(data) {
if(data instanceof Error) {
console.log("url error");
process.exit(1);
}else {return data}
};
});
};
this function downloads a webpage and returns it content but when i call it in the program it return undefined. how do i solve this problem by the way when called on it own it works fine
After careful research i realized that this function is an asynchronous operation and so will program execution will continue whiles the function function runs in the background.
to solve this problem put all the code need to process the data been return right in the else statement