【问题标题】:How to use node js with API如何通过 API 使用 node js
【发布时间】:2020-11-14 00:04:52
【问题描述】:

我正在使用来自 https://brokersports.ddns.net/ 的运动 API 我在 node.js 中的这段代码有问题,它允许显示来自 API 的数据:

request.get("https://brokersports.ddns.net/api/v2/soccer/")
        .header("Authorization", "Bearer m_key")
        .header("Accept", "application/json")
        .end(function (result) {
        console.log(result.status, result.headers, result.body);
        });

这段代码不工作,我不知道为什么

我在控制台中有这个错误:

Uncaught ReferenceError: request is not defined

有人可以帮助我!!

【问题讨论】:

    标签: node.js api http


    【解决方案1】:

    要使用request module,您必须使用install it,然后使用requireimport 将其加载到您的模块中(取决于您是在编写CommonJS 模块(默认)还是ES6 模块)。

    (如果您尚未使用package.json 创建项目,请启动with this tutorial)。

    但不要使用 request 模块:它已被弃用。切换到支持的内容,例如 axiosnode-fetch。尽管如此,以上所有内容仍然适用于这些模块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 2017-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多