I often start up the Node Js terminal to run small tasks or inspect some data. A current limitation is that I can't wait for an async function:
mymachine$ node
> const request = require('request-promise-native')
undefined
> await request('https://google.com')
Thrown:
await request('https://google.com')
^^^^^
SyntaxError: await is only valid in async function
I end up having to do things like this
> let data;
undefined
> request('https://google.com').then(x => data = x)
Promise { <pending> }
> data.length
46262
but there are some inconveniences associated with this. Is there any other alternative so that I can chain a sequence of await
commands in the node terminal?
Via this site:
Top Level Await is supported in Node version 10's REPL if you enable it with the --experimental-repl-await
flag.
The official documentation is here and still requires the command line switch as of version 13.10.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With