Node.js FAQ: Top Questions
9. What is async/await in Node.js?
async/await is a syntactic sugar over Promises, allowing asynchronous code to be written in a synchronous-looking style, introduced in Node.js 8 (ES2017).
- async: Declares a function that returns a Promise.
-
await:
Pauses execution until a Promise resolves, only in
asyncfunctions. -
Error Handling:
Use
try/catchfor errors. - Use Case: Clean, readable async code.
