Facebook Pixel

How do callbacks flow through the event loop in Node.js?

An async operation starts, the operation completes in libuv, libuv queues the callback, and the event loop picks it up in the appropriate phase on the next tick. The callback runs on the main thread, never on a separate thread.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Node.js Event Loop Deep Dive: How It Actually Works

A single-threaded loop that processes callbacks from completed async operations through phases: timers, pending callbacks, poll, check, and close. It makes Node.js non-blocking by handling I/O asynchronously through libuv while processing one callback at a time.

Timers (setTimeout), pending callbacks (deferred I/O), idle/prepare (internal), poll (new I/O events and most I/O callbacks), check (setImmediate), and close callbacks (cleanup). Each processes specific callback types in order.

After each phase and after each callback, microtasks run. process.nextTick callbacks run before promise callbacks, both before the next macrotask. This is why promise callbacks run before the next setTimeout or I/O callback.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.