I have a function that uses the module cherio to get data from a website.
Now I\'d like to iterate this function over an array of keywords, collect the intermediate
Promise is the best solution for handling asynchronous operations.
Promise.all(search_words.map(function(keyword) {
return new Promise(function(resolve, reject) {
request(base_url + keyword + "&l=", function(err, resp, body) {
if (err) {
return reject(err);
}
$ = cheerio.load(body);
resolve([keyword, $("#searchCount")[0].children[0].data.split(" ").reverse()[0]]);
});
});
})).then(function(stats) {
console.log(stats);
});