Facebook Pixel

When do microtasks run in the Node.js event loop?

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.

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.

Understanding it explains the order of async callbacks, why setTimeout(0) does not run immediately, and why blocking synchronous code stops everything. This is core Node.js knowledge for interviews and production debugging.

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.