【发布时间】:2022-12-03 03:58:06
【问题描述】:
我正在尝试将 2022 Advent Of Code 中的数据提取到 Vscode 中,而无需将数百行原始数据复制并粘贴到我的 IDE 中。
let response = await fetch('https://adventofcode.com/2022/day/1/input')
let text = await response.text()
console.log(text)
这段代码在浏览器开发工具中运行完美,但是当我尝试在节点中运行它时,出现SyntaxError: await is only valid in async functions and the top level bodies of modules的错误
【问题讨论】:
-
在异步函数中添加此代码