Using await/async in a Simple Script

Henry Williams on May 23, 2019

Problem: You want to use await/async at the top-level of your simple script like so: async function asyncFunction() { return new Promise(re... [Read Full]
markdown guide
 

Henry I like your idea here. What are your thoughts on where this could be a bad coding pattern and also where this would be a good pattern to use?

 

I generally don't like to use this pattern except for initializing something like a database connection or something of the sort at the end of the script.


module.exports.runQuery = async query => {
    ....
}

(async () => {
    await initializeDatabase()
})()
code of conduct - report abuse