AsynchronousLesson 12Free preview
Node Async/Await
This lesson is part of Node.js · All levels
Summary
Async/await is the syntax above Promise that makes asynchronous code look like synchronous code without sacrificing the non-blocking nature. Function async always returns the Promise, while await waits for the Promise result before moving on to the next line. The error can be handled with try/catch so the handling is much cleaner.
Key points
- Always return the Promise even if there is no explicit
- Await is valid only within function async (or top-level ESM modules)
- The code after await is run as a continuation, not a blocking thread
- Use try/catch to capture the error of the operation
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.