A request handler may need to read a file or query a database before it can respond. Waiting for that result must not block JavaScript from handling other events. `async` and `await` let promise-based operations read like sequential code without giving up non-blocking behavior. section 3.1 section 8.2.1
`await value` converts `value` to a promise, as `Promise.resolve(value)` would, and pauses the surrounding execution until that promise settles. While it is pending, the event loop can process other events. A fulfilled promise resumes execution with its value; a rejected promise throws its reason at the `await` expression. Resumption is queued as a microtask, much like a `then` callback. section 8.2.2
async function indexHandler(req, res) {
const html = await fsPromises.readFile("index.html", "utf8");
res.send(html);
}
The request handler awaits a promise-based file read, then sends the resulting HTML. The code is written in order, but the pending read does not block other events. section 3.1
This helps when later steps need earlier results. Nested callbacks keep that state in scope but can become hard to read; separating them requires passing state around explicitly. With `await`, authentication, a database query, and rendering can remain in one readable flow. Ordinary `try`/`catch` can handle a rejected awaited operation. section 8.2.1 section 8.2.2
Keep these boundaries in mind:
- `await` is allowed inside an `async` function or at the top level of an ECMAScript module—not anywhere in JavaScript code. section 8.2.2
- An `async` function always returns a promise. Its returned value or thrown error determines how that promise settles. section 8.4
- Sequential-looking syntax does not create another JavaScript thread. It replaces common promise callback patterns while leaving other events free to run. section 8.1 section 8.2.2



















