Async/Await — Complete Guide
Async/Await — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of Node.js Tutorial on Toolliyo Academy.
On this page
Async/Await
This lesson covers Async/Await. You do not need to memorize everything. Understand the flow first.
What you will learn
- What async/await means — in normal words, not textbook words
- How it works step by step
- Code you can run today on your laptop
- Where teams use this in real projects
Before you start
- Software: Node.js LTS from nodejs.org, VS Code, and a terminal
- Knowledge: Earlier lessons in this Node.js course
- Previous lesson: Promises — Complete Guide
Explain it simply
async/await is syntax on top of Promises. You write async code that looks synchronous but still does not block the server.
Why developers use this
- Easiest to read and maintain
- try/catch for errors
- Standard in modern Node and Express handlers
How it works (step by step)
- Your code starts a task (read file, query DB, timer).
- Node continues other work instead of waiting idle.
- When the task finishes, your callback, Promise, or
awaitruns. - Errors go in
catchor.catch()— never ignore them.
Code example — type this yourself
const fs = require('fs/promises');
async function loadConfig() {
try {
const raw = await fs.readFile('config.json', 'utf8');
return JSON.parse(raw);
} catch (err) {
console.error('Config missing, using defaults');
return { port: 3000 };
}
}
await pauses only inside the async function — other requests can still run.
What each part does
const fs = require('fs/promises');— Loads a built-in module or package you installed with npm.async function loadConfig() {— Async work — Node can serve other users while this waits.try {— Catches errors so one failure does not crash the whole server.const raw = await fs.readFile('config.json', 'utf8');— Async work — Node can serve other users while this waits.return JSON.parse(raw);— Line 5: runs as written.} catch (err) {— Catches errors so one failure does not crash the whole server.console.error('Config missing, using defaults');— Line 7: runs as written.return { port: 3000 };— Line 8: runs as written.
Real life: where Async/Await shows up
An online store uses Async/Await so hundreds of users can check order status at once. While one request waits for the database, Node handles other users instead of freezing. Start small: one feature working beats a perfect architecture on paper.
Try it yourself — hands-on
- Create config.json with {"port":4000}
- Call loadConfig() from an async main()
- Delete config.json and see the fallback
Common mistakes (avoid these)
- Using await without async — syntax error.
Interview note
Interviewers often ask: “What is Async/Await?” Answer in one sentence, then give a tiny example you actually ran.
Summary
- async functions return Promises
- await waits for a Promise
- Use try/catch for errors
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!