Node.jsQuestion 05 of 26
Asynchronous programming
Answer out loud or in your head first, then compare.
Answer
An operation can start now and its result arrive later. While it waits for I/O, Node can handle other events.
JavaScript
import { readFile } from 'node:fs/promises';
async function readConfig() {
const text = await readFile('config.json', 'utf8');
return JSON.parse(text);
}To be precise: await pauses the rest of that function, not the whole process. Marking a function async doesn't move computation to another thread.
Pitfall: a long synchronous loop still blocks the event loop, even inside an async function.
How did it go? Be honest — “Not yet” puts the question on your review list.