Node.js · Junior · Question 37 of 75

Can you use await at the top level of a file (outside any function) in Node.js?

Explanation

Top-level await is part of ES modules. In CommonJS you must wrap the code in an async function.

Further reading

Problem with a question

Node.js · Junior · question 37

Test yourself

Take the Node.js · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz