Answer the question
In order to leave comments, you need to log in
Can a callback return multiple parameters?
I am writing a parser, this is a function that counts the number of pages
var request = require('request');
var cheerio = require('cheerio');
var counter = function (link, i, callback) {
request(link + i, function (error, response, body) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(body);
if ($('.b-products__list .main-bigger3').text().trim() == 'К сожалению, в данной категории нет товаров') {
callback(link ,--i);
}
else {
counter(link, ++i, callback);
}
}
})
};
module.exports = counter;
Error: Can't set headers after they are sent.
Answer the question
In order to leave comments, you need to log in
You can pass any number of parameters to the callback, but it is customary to make the first parameter error. The error is in the code from which you call this module. One can only guess, but most likely, the top-level code somehow checks the first parameter of the callback, try passing null as the first parameter, or give the code to the studio.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question