Node.js Async

Async behavior is central to Node. Learn how the event loop, promises, and async functions keep I/O responsive.

Event loop

Node schedules I/O work instead of blocking the process. That design makes it efficient for servers and tooling.

Promises

function wait(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

async/await

async function run() {
  await wait(100);
  console.log("done");
}

Practice

  1. Write one promise that resolves after a timeout.
  2. Wrap it in an async function and await the result.
  3. Explain why blocking the event loop hurts throughput.