I'm a beginner with js and nodejs. I'm writing a simple program, which loads and parses array of urls with help of request
and cheerio
modules. It takes me really long time to parse array, which contains about 700 urls, about 40 seconds. So, I'm searching for something, which can help me to increase the speed of execution. I tried Parallel
module, using map
, but that leads my request
function to being undefined for some unknown reason... I've also heard about async module, but as I know js still remains single-threaded with it. Could someone give me advice what to use to reduce the time of execution, please?
Here is my try:
var p = new Parallel(Arr);
p.map(GetGenres);`
var GetGenres = function(value){
request(value.url, function(err, res, body){
var $ = cheerio.load(body, { xmlMode: true });
value['genres'] = [];
$('div').has('span:contains("Genres:")')
.children('a')
.each(function(i, element){
value.genres.push($(this).text());
})
});
};