-1

Node js is a single-threaded application even though it executes the asynchronous operation my initial understanding about this was like this “The Event loop runs in a separate thread in the user code. There is a main thread where the JavaScript code of the user (userland code) runs in and another one that runs the event loop. Every time an asynchronous operation takes place, the main thread will hand over the work to the event loop thread and once it is done, the event loop thread will ping the main thread to execute a callback.” And this article explains to me it is wrong. https://www.freecodecamp.org/news/walking-inside-nodejs-event-loop-85caeca391a9/

Also, I have seen that there is some code return result after the first part is executed even though that part is called after the first part. I am getting terribly confused here can someone is able to help me with this?

Also what is libuv has to do with this?

AdminRoy
  • 105
  • 1
  • 8
  • Perhaps one of these existing Stack Overflow posts on the topic would be helpful? : [1](https://stackoverflow.com/questions/17959663/why-is-node-js-single-threaded) [2](https://stackoverflow.com/questions/14795145/how-the-single-threaded-non-blocking-io-model-works-in-node-js) [3](https://stackoverflow.com/questions/10570246/what-is-non-blocking-or-asynchronous-i-o-in-node-js/10570261) [4](https://stackoverflow.com/questions/16336367/what-is-the-difference-between-synchronous-and-asynchronous-programming-in-node/16336405) – Alexander Nied Oct 23 '19 at 03:48

1 Answers1

0

Single thread means event queue runs in a single thread. In the background there are other threads that runs jobs like IO. There is a thread pool for them but you are not interested in the internals of that as a developer. That simplifies handling of the blocking IO tasks for the application developer. You just send a request and register for the result of your task and run your code in the callback.

Behlül
  • 3,412
  • 2
  • 29
  • 46