What is Event loop in Node.js work? And How does it work?

 The Event loop handles all async callbacks. Node.js (or JavaScript) is a single-threaded, event-driven language. This means that we can attach listeners to events, and when a said event fires, the listener executes the callback we provided.

Whenever we are calling setTimeouthttp.get and fs.readFile, Node.js runs these operations and further continues to run other code without waiting for the output. When the operation is finished, it receives the output and runs our callback function.

So all the callback functions are queued in a loop and will run one-by-one when the response has been received

Comments

Popular posts from this blog

Which node logger did you use in your project?

What is promise, promise.all and promise.race? How do you chain promises?