How was Node.js built to be asynchronous if JavaScript is synchronous?

advertisements

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.


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.