2

Possible Duplicate:
Internals of node.js. How does it actually work

I am new to NodeJS and I am confused with how the event loop works.

Firstly, if I have a blank file (lets say it is called blank.js), and I run it with node (node blank.js), then node runs the file and exits immediately. Why didn't the event loop start, and what makes it start?

Secondly, when running a server on NodeJS, the server is effectively waiting for input (i.e. a client request). What is happening when it is waiting, and how is it waiting (it is not sleeping, that I am sure because it would make hold up the event loop). The way node has been described, it is evented (therefore it is waiting for an event), but how is it doing this then?

Lastly, Ryan Dahl describes Node as a single stack. What I think is that due to the event nature of Node, function calls do not have a stack like what would be present in a recursive call. Is this correct?

So summarise my questions:

  1. What starts the event loop, and how does it start?
  2. When Node is waiting (this is non-blocking), how is this accomplished?
  3. What happens to the function memory stack for functions that are used for callbacks?

I have read books on NodeJS, and yes, I realise that Nodes is asynchronous single threaded non-blocking IO. I just don't know how the internals work, and no book is telling me this.

Community
  • 1
  • 1
Barry Steyn
  • 1,563
  • 3
  • 19
  • 25
  • this might clear things out about node event loop : http://stackoverflow.com/questions/10680601/nodejs-event-loop – soulcheck Nov 22 '12 at 16:53
  • @soulcheck I have read this article before posting this. It does not clear things up. The videos etc just explain asynch IO on a high level basis – Barry Steyn Nov 22 '12 at 17:59
  • It's not waiting, execution goes on (or stops if program ends). Callback is like registered listener that gets called when the async function is done. – Marko Bonaci Nov 23 '12 at 19:42

0 Answers0