Top level async in node scripts
Write async-await in mjs files and run as scripts
Toni PetrinaPublished on 2022-02-05•1 min read
To run async code in a script, use:
mjs
extensionNODE_OPTIONS='--experimental-json-modules'
Inside package.json
:
"script-name": "NODE_OPTIONS='--experimental-json-modules' && node ./path/to/script.mjs",
Then write any kind of async
code in the top level:
await fs.writeFile("file");