【问题标题】:Use fast.com API with Angular将 fast.com API 与 Angular 一起使用
【发布时间】:2020-12-22 22:15:41
【问题描述】:

我是角度新手。我正在构建一个 speedtest 网站作为一个辅助项目,并决定使用 fast.com API. 在我的 component.ts 中,我包含以下内容:

constructor() {
    const FastSpeedtest = require('fast-speedtest-api');

    const speedtest = new FastSpeedtest({
      token: 'myToken', // required
      verbose: false, // default: false
      timeout: 10000, // default: 5000
      https: true, // default: true
      urlCount: 5, // default: 5
      bufferSize: 8, // default: 8
      unit: FastSpeedtest.UNITS.Mbps, // default: Bps
      proxy: 'http://optional:auth@my-proxy:123', // default: undefined
    });

    speedtest
      .getSpeed()
      .then((s) => {
        console.log(`Speed: ${s} Mbps`);
      })
      .catch((e) => {
        console.error(e.message);
      });
  }

但是当我运行ng serve 时,我得到以下角度错误:

Failed to compile.

./node_modules/fast-speedtest-api/src/Api.js
Module not found: Error: Can't resolve 'http' in 'C:\Users\sacre\Documents\GitHub\speedtest\node_modules\fast-speedtest-api\src'

有人知道为什么会这样吗?

【问题讨论】:

    标签: node.js angular speed-test


    【解决方案1】:

    已编辑

    Github issue - Angular Integration #4

    这是与 NodeJS 一起使用的。由于它使用 NodeJS API,因此无法在浏览器中按原样运行。

    基于不支持在 angular 运行的浏览器中运行此 api。

    【讨论】:

    • ./node_modules/fast-speedtest-api/src/Api.js Module not found: Error: Can't resolve 'http' in 'C:\Users\sacre\Documents\GitHub\speedtest\node_modules\fast-speedtest-api\src'
    • 是的,我已经安装了包
    • 你确定这实际上不是一个节点模块..?
    • @CarlosDaniel - 我找到了答案,虽然它不是你要找的。​​span>
    • @Igor 我最终创建了一个服务器,这是项目:github.com/carlos-dubon/speedtest
    猜你喜欢
    • 1970-01-01
    • 2014-12-22
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    相关资源
    最近更新 更多