Facebook Pixel

What are microtasks and macrotasks in Node.js?

Microtasks are process.nextTick and promise callbacks, which run after the current operation and before the next macrotask. Macrotasks are setTimeout, setImmediate, and I/O callbacks, which run one per event loop phase.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Node.js Event Loop Interview Questions With Answers

A single-threaded loop that processes callbacks from completed async operations through phases: timers, pending, poll, check, 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), check (setImmediate), and close callbacks. Each processes specific callback types in order through each tick of the loop.

setTimeout runs in the timers phase after a delay. setImmediate runs in the check phase right after poll. On the next tick, setImmediate usually runs before setTimeout(0) when there are no pending timers.

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.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.