Fel*_*ipe 1 javascript terminal node.js
我经常启动Node Js终端以运行小任务或检查一些数据。当前的局限性是我不能等待异步功能:
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
Run Code Online (Sandbox Code Playgroud)
我最终不得不做这样的事情
> let data;
undefined
> request('https://google.com').then(x => data = x)
Promise { <pending> }
> data.length
46262
Run Code Online (Sandbox Code Playgroud)
但这带来一些不便。还有其他选择可以使我await在节点终端中链接一系列命令吗?