So, I'm lost on how to handle this properly.
What I want to do is:
// client side
Meteor.call("getData", url, function(images) {
console.log(images); // get array of image src
});
// server side
Meteor.methods({
"getData": (url) => {
var images = [];
// here is where I am lost
// scrape the images
scrape.request(url, function(err, $) {
if (!err) {
$('img').each(function(img) {
let src = img.attribs.src;
images.push(src);
}
// so at this point, I can console log an array on the server, but I need to bring it back to the client
}
} // now, how do I push all these and then signal to return the array?
return images; // returns undefined, not waiting for all the data
// I'm not sure how to wait for the array to be updated.
}});
Thoughts?
So, recap, I want to get an array back of all the image sources scraped from the website passed to the Meteor method.