Event loop

The event loop is the mechanism that lets Node run JavaScript on a single thread while handling many I/O operations. It processes queued callbacks when the call stack is empty; microtasks (promises) run before timers. A long computation blocks it.

Example

setTimeout(() => console.log('B'), 0);
Promise.resolve().then(() => console.log('A')); // A then B

Related concepts

The whole glossary