I'm new to angular. I'm building a speedtest website as a side project and decided to use fast.com API. In my component.ts I've included the following:
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);
});
}
But when I run ng serve
I get the following error in angular:
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'
Anyone knows why this is happening?
edited
See Github issue - Angular Integration #4
This is ment to be used with NodeJS. Since it uses NodeJS APIs it won't work in the browser as is.
Based on that it is not supported to run this api within the browser which is where angular runs.