I will explain my question with example.
fs.readFile('somefilename', function(err, data) {
...doSomething...
});
When this line of code is executed readFile will start reading the file. On success or failure this callback will be pushed into queue for execution with appropriate arguments.
Reading of file is happening asynchronously, but who's doing it if NodeJS is single threaded, non-blocking?
User code is executed in a single thread. However, behind the scenes nodejs uses libuv/libio to handle any io which does use threads.
https://github.com/libuv/libuv
Interesting posts:
How the single threaded non blocking IO model works in Node.js
Does node.js use threads/thread pool internally?
Why is Node.js single threaded?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With