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:
- What starts the event loop, and how does it start?
- When Node is waiting (this is non-blocking), how is this accomplished?
- 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.