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 setTimeout
, http.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
Post a Comment