I am trying to use a node-image-scraper package to scrape some images from a webpage, then return the array of images to the client in Meteor. However, I currently have no idea how this would work given the event driven nature of the pack.
var imageScraper = new imagescraper();
var images;
Meteor.methods({
scrapeImgs(url){
imageScraper.on('image', (image) => {
images.push(image);
});
images = [];
imageScraper.address = url;
imageScraper.scrape();
imageScraper.on('end', () => {
return images; //does not work
});
return images; // returns an empty array
},
});
Returning images from the event does not work, and returning images outside returns an empty array. Is there any way to make this work? Or is it fundamentally not possible given the circumstances? How would this be done if I need to return the full set of images to the client?