Most modern Node APIs expose Promise versions—often under fs/promises or with util.promisify. Chain with .then/.catch or use async/await for readability.
Promise basics
import { readFile } from 'node:fs/promises';
readFile('config.json', 'utf8')
.then(JSON.parse)
.then(config => console.log(config.port))
.catch(err => console.error(err));
Promise.all
Run independent async tasks in parallel—fails fast if any reject. Use Promise.allSettled when you need every result regardless of failures.
Important interview questions and answers
- Q: Unhandled promise rejection?
A: Node emitsunhandledRejection—always attach.catchor try/catch around await in async functions. - Q: Promise.all vs sequential await?
A:allparallelizes independent work; sequential await in a loop waits each iteration—slower for I/O that could overlap.
Self-check
- When does Promise.all reject?
- Where do fs promise APIs live?
Interview prep
- fs.promises vs callback fs?
fs.promisesreturns Promises for async/await; callback style nests error-first functions—prefer promises in modern code.