Currently i have this code
function DownloadPage(uri) {
request(uri, function (err, res, body) {
if (err) {
console.log(err);
} else {
nextURL = FindURLBySomeLogic(body);
DownloadPage(nextURL);
}
});
}
DownloadPage("http://example.com/");
but i think that i will get stack overflow after some amount of pages. Amount of pages are infinite. How can I avoid this? Every page contain only JSON data.
console.log(new Error().stack);
in DownloadPage
will show you that the stack size does not increase because request
is async.