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
- Write one promise that resolves after a timeout.
- Wrap it in an async function and await the result.
- Explain why blocking the event loop hurts throughput.