Does Node.js offloads actual I/O operations to underlying operating system to achieve a so-called non-blocking I/O?
I am just newbie in Node.js world so please bear with me.
When Node.js app server receives concurrent requests, it will process them one by one in sequential order due to nature of single-threaded language. Now the most interesting part is how Node.js app server handles requests then respond back to every client. Basically, if handling request requires:
- CPU intensive computation, we can spawn a worker process to do the job, once computation has completed we send an event of completion to master which is even-loop thread, registered callback is invoked and send response back to client.
- database connection, reading file on server... (this is I/O operation), here we don't have to manually spawn a worker process, all we need to do is register a callback which is going to be invoked when I/O result available. My question is right here, who is handling I/O stream (operation) under the hood (Operating System or a certain process that we are not aware of spawn by Node.js ???? ) and send event of completion to event-loop ?