异步并在Node中的app.js文件中等待?

时间:2020-10-12 07:50:16

标签: node.js asynchronous async-await

app.get("/", function (req, res) {
  async function showData() {
    const res = await fetch("api.openweathermap.org/data/2.5/weather?q=Berlin&appid={apiID}");
    const data = await res.json();
    console.log(data);
  }
})

///当我运行节点app.js时,这应该将数据记录在终端中,但出现错误。

1 个答案:

答案 0 :(得分:0)

Fetch返回响应流。 检出answer to this question。使用request-promise / request模块或处理fetch返回的流。