Guided Notes

Asynchronous Programming: Callbacks, Promises & async/await

How async code runs in Node, callbacks and their problems, promises, async/await, running tasks in parallel, timeouts and error handling.

Why async

Slide 1 / 5

Reading a file or calling an API takes milliseconds to seconds. Instead of waiting idly, Node starts the operation and continues; when the result arrives, your code continues from where it left off.

Three generations of async style: 1. Callbacks — fs.readFile(p, (err, data) => …) 2. Promises — readFile(p).then(…).catch(…) 3. async/await — const data = await readFile(p) (modern default)

← Events & the EventEmitter