Reputation: 3509
I understand that Node.js is asynchronous and I understand what this means from a developer's point of view. I get the whole restaurant examples and non-programming perspectives. What I don't get is how JavaScript, which is (largely?) synchronous, was used in order to build Node. How is this achieved? What I would like to see is a simple code example of how a function is made to run somewhere in the background, while the rest of the code just keeps running.
Upvotes: 0
Views: 62
Reputation: 3509
I guess a slightly better answer than what christianalfoni posted would be the following:
Node.js is build on top of V8 (Chrome's Javascript engine) + libuv, which is described as "a multi-platform support library with a focus on asynchronous I/O".
Whenever Node does anything asynchronous, that is handled by libuv behind the covers. So, in a way, yes, Node.js is more C++ than it is Javascript, but C++ is also synchronous by nature, so that would not explain why you can have callbacks in Node/JS in the browser.
Upvotes: 0
Reputation: 1034
Node is not javascript. Node is C++. You have a JavaScript layer that talks to an underlying layer that very simply said works pretty much like xmlHttpRequest in the browser. The xmlHttpRequest itself is not javascript, its another process underneath the handles it. So there is no JavaScript running in the background in Node.
Upvotes: 3