Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Looks like you got some recursion going on there. Recursive function calls will eventually exceed the stack since this is where function pointers are stored.</p> <p>So here is how it happens:</p> <ol> <li>fetch calls extract in the request.get callback</li> <li>extract calls push in the mongo.pages.find callback</li> <li>push calls fetch inside the while loop</li> </ol> <p>This cycle seems to repeat until you run out of stack.</p> <p>In your case the stack is running very low by the time you call <code>cheerio.load</code> which is why it runs out right then and there.</p> <p>Although you most likely want to examine if that is a bug or something you intended, in order to get the same effect in nodejs without using straight recursion is to use:</p> <p><code>process.nextTick(functionToCall)</code>.</p> <p>It will leave the enclosed function, which pops its pointer off the stack, but call the <code>functionToCall</code> on the next tick.</p> <p>You can try it in the noderepl: </p> <p><code>process.nextTick(function () { console.log('hello'); })</code></p> <p>will print 'hello' immediately.</p> <p>Its simliar to <code>setTimeout(functionToCall, 0)</code>, but to be preferred over it.</p> <p>Relating to your code you could replace <code>self.fetch(url)</code> with <code>process.nextTick(function () { self.fetch(url); })</code> and should no longer run out of stack.</p> <p>That being said, as mentioned above, it is more likely that there is a bug in your code, so look into that first.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload