GithubHelp home page GithubHelp logo

speedtest.net's Introduction

speedtest.net API / CLI tool

SpeedTest Cli

Installation

npm install --save speedtest-net

Command-Line Tool

$ npm install --global speedtest-net
$ speedtest-net

Usage

The whole speed test runs automatically, but a lot of events are available to get more info than you need.

The test comes in two versions. The main one is for use by code, and then there's a command line utility.

Code use example:

const speedTest = require('speedtest-net');

(async () => {
  try {
    console.log(await speedTest());
  } catch (err) {
    console.log(err.message);
  } finally {
    process.exit(0);
  }
})();

CLI options

Usage: speedtest-net [-h|--help] [--accept-license] [--server-id <id>] [--source-ip <ip>]

  • -h, --help: Help
  • --accept-license: Accept the Ookla EULA, TOS and Privacy policy. The terms only need to be accepted once.
  • --accept-gdpr: Accept the Ookla GDPR terms. The terms only need to be accepted once.
  • --server-id <id>: Test using a specific server by Ookla server ID
  • --source-ip <ip>: Test a specific network interface identified by local IP

Module use options

You can pass an optional options object.

The options include:

  • serverId: string ID of the server to restrict the tests against.
  • sourceIp: string IP of the network interface to bind
  • progress: function Function to handle progress events
  • binary: string Binary executable path of the Ookla speedtest CLI
  • binaryVersion: string Default '1.0.0' Binary executable version
  • host: string Server host to connect to
  • verbosity: number Log level for { type: log } progress events
  • acceptLicense: boolean Set to true to accept the Ookla EULA, TOS and Privacy policy. This must be done (at least) once on the system. If you have not accepted the Ookla license terms, you can view the links to their agreements by running the speedtest-net CLI without the --accept-license option.
  • acceptGdpr: boolean Set to true to accept the Ookla GDPR terms. This must be done (at least) once on the system. If you have not accepted the Ookla GDPR terms you can read their disclaimer by running the speedtest-net CLI without the --accept-license option.
  • cancel: function A cancellation function created with speedTest.makeCancel() to cancel the test (See Canceling Tests).

Progress Events

Each progress event has a type property which will be one of:

  • 'config'
  • 'log'
  • 'testStart'
  • 'ping'
  • 'download'
  • 'upload'

Each event contains a progress property at the root which indicates the overall progress of the test as a fraction (0 to 1).

The ping, download and upload events also contain a progress property inside the content data object (with the same name as the event name) which indicates the progress of the current test.

All events except config contain a timestamp property which will be a Date object.

Config event

This event is only sent when the verbosity is 2 or greater. It contains a bunch of information about the test:

{
  type: 'config',
  progress: 0,
  suite: {
    global: {
      engine: {
        threadCount: 4,
        testDurationSeconds: 15,
        packetSizeBytes: 32000000,
        isUploadFirst: false
      },
      dynamic: {
        stableStop: { isEnabled: true },
        download: { isScalingEnabled: true, maxThreadCount: 32 }
      }
    },
    testStage: {
      latency: { pingCount: 5 },
      upload: {
        isServerUploadEnabled: true,
        isClientPrimaryMeasureMethod: false
      }
    }
  },
  app: {
    traceLevel: 2,
    ispName: 'Slower Web Inc',
    licenseKey: '408003aeea741916-C93ad77cb653213a5-a3d0efbb2e3723d4',
    saveTestResultUrl: 'https://results.speedtest.net/reports',
    resultFormat: 'json',
    license: {
      message: 'You may only use this Speedtest software and information generated\nfrom it for personal, non-commercial use, through a command line\ninterface on a personal computer. Your use of this software is subject\nto the End User License Agreement, Terms of Use and Privacy Policy at\nthese URLs:\n\n\thttps://www.speedtest.net/about/eula\n\thttps://www.speedtest.net/about/terms\n\thttps://www.speedtest.net/about/privacy',
      version: 'a754f1d8862e34fda3a580af273344e3b7b892fb5a8eb755f1f639aaf8b30bdf'
    }
  },
  servers: [
    {
      id: '1234',
      host_functional: '1',
      host: 'speedtest.someserver.net:8080',
      name: 'Awesome test server',
      country: 'United States',
      sponsor: 'United people of the world'
    },
    {
      id: '1235',
      host_functional: '1',
      host: 'supertestserver.net:8080',
      name: 'Cruddy test server',
      country: 'United States',
      sponsor: 'Some company'
    }
  ]
}

Log event

These are various log messages. Only sent when verbosity is 1 or greater. Higher verbosity leads to more messages. That's all I know.

Each log is associated with a log level. Levels include info and warning and may include others.

{
  type: 'log',
  progress: 0.7391304347826086,
  timestamp: [Date],
  message: 'Starting stage 3 of type 4',
  level: 'info'
}

Test start Event

This contains information about the test to be run.

{
  type: 'testStart',
  progress: 0,
  timestamp: [Date],
  isp: 'Slower Web Inc',
  interface: {
    internalIp: '10.1.1.10',
    name: '',
    macAddr: '00:FE:C1:12:4A:ZX',
    isVpn: false,
    externalIp: '104.1.1.17'
  },
  server: {
    id: 1234,
    host_functional: '1',
    name: 'Awesome test server',
    location: 'New York, NY',
    country: 'United States',
    host: 'speedtest.someserver.net:8080',
    port: 8080,
    ip: '192.1.1.3'
  }
}

Ping event

Sent when the test is in the ping phase. Jitter and latency are in milliseconds.

{
  type: 'ping',
  progress: 0.034782608695652174,
  timestamp: [Date],
  ping: { jitter: 1.297, latency: 12.363, progress: 0.4 }
}

Download event

Sent when the test is in the download phase. Bandwidth is in bytes per second.

{
      type: 'download',
      progress: 0.205523,
      timestamp: [Date],
      download: {
        bandwidth: 116904636,
        bytes: 334816510,
        elapsed: 2727,
        progress: 0.18180193333333333
      }
    }

Upload event

Sent when the test is in the upload phase. Bandwidth is in bytes per second.

{
  type: 'upload',
  progress: 0.8351304347826086,
  timestamp: [Date],
  upload: {
    bandwidth: 3625125,
    bytes: 19799551,
    elapsed: 5520,
    progress: 0.368
  }
}

Return value

The speedTest function returns a promise that resolves to an object with the following shape:

{
  timestamp: [Date],
  ping: { jitter: 1.022, latency: 12.363 },
  download: { bandwidth: 87757724, bytes: 959666451, elapsed: 10804 },
  upload: { bandwidth: 3701179, bytes: 35468808, elapsed: 9703 },
  packetLoss: 8.837209302325581,
  isp: 'Slower Web Inc',
  interface: {
    internalIp: '10.1.1.10',
    name: '',
    macAddr: '00:FE:C1:12:4A:ZX',
    isVpn: false,
    externalIp: '104.1.1.17'
  },
  server: {
    id: 1234,
    host_functional: '1',
    name: 'Awesome test server',
    location: 'New York, NY',
    country: 'United States',
    host: 'speedtest.someserver.net:8080',
    port: 8080,
    ip: '192.1.1.3'
  },
  result: {
    id: 'd5ac8c40-3d69-39ac-cfc1-3b349df780e9',
    url: 'https://www.speedtest.net/result/c/d5ac8c40-3d69-39ac-cfc1-3b349df780e9'
  }
}

Canceling Tests

You can cancel tests by creating a test canceler with makeCancel(). Then pass this canceler to the test. Now, when the canceler is called, the test will be terminated. The promise will reject with an error.

If the canceler is called before the test is started, the test will abort before starting.

Canceler functions are not meant to be reused.

const speedTest = require('speedtest-net');

(async () => {
  try {
    const cancel = speedTest.makeCancel();
    setTimeout(cancel, 1000);
    console.log(await speedTest({ cancel }));
  } catch (err) {
    console.log(err.message);
  } finally {
    process.exit(0);
  }
})();

Considerations

This uses the official Ookla command line client so the results should be the same as the speedtest.net tests you can run in the browser.

When running the speed test for the first time you may get an error indicating you need to accept the Ookla license terms. For the CLI you can pass the --accept-license option. For the module, you can pass the { acceptLicense: true } option. If you're located in Europe you might need to accept the additional GDPR terms, this can be done by passing --accept-gdpr for the CLI and the { acceptGdpr: true } option when used as a module.

When running the test for the first time, and a CLI binary is not yet available, the client will be automatically downloaded from the Ookla server and unpacked. The file will then be marked as executable. This step may fail if the calling process does not have sufficient permissions. To get around this, you can pass either a custom binary option (module only), or manually mark the file as executable. The latter option is not recommended since this can break if you need to run npm install or yarn.

License

MIT

speedtest.net's People

Contributors

amilajack avatar beau6183 avatar brettmarl avatar brigand avatar christoph-neumann avatar clarkio avatar ddsol avatar devildant avatar djlegolas avatar fvdm avatar fvictorio avatar imagdy avatar ivanseidel avatar jsejcksn avatar khatada avatar kitsunekyo avatar lipedjow avatar luigimannoni avatar matiasbontempo avatar matthewhadley avatar nathanielwood avatar palerdot avatar philmod avatar si458 avatar whoaa512 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

speedtest.net's Issues

Document "correction factor" methodology in README

I see this comment:

// These numbers were obtained by measuring and averaging both using this module and the official speedtest.net

Perhaps you can provide in README.md more detail about the methodology for deriving the correction factors so that others can understand exactly how and why these factors are used. This is extremely important for understanding the quality of information provided by this module.

proxy support

Hello,

would it be possible to have proxies support via environment variables or via options?

best regards

#8

Linting issues

I know it's a matter of taste, but I'm working on some speed reporting issues (consistently slower speeds from this tool being reported than what the speedtest.net interface reports), and the linting issues are just annoying me. Would you be opposed to me fixing up the formatting and such so that lint stops complaining? Obviously it would be in a pull request of its own as to not introduce new functionality on top.

Licensing and terms of use

Hoi, do you know if any terms or license apply from Ookla when we use their servers like this in our own applications? It's not mentioned on their website in any way.

avoid xml usage?

Is it possible to avoid XML usage at all? I'd like to use this on my Tessel, but I can't, because the XML serialization runs me out of memory.

Angular Integration

Can this plugin be used with angular...???
I have tried to use it but getting these errors:

ERROR in ./node_modules/speedtest-net/index.js
Module not found: Error: Can't resolve 'crypto' in '/home/hash/speedtest/node_modules/speedtest-net'
ERROR in ./node_modules/speedtest-net/index.js
Module not found: Error: Can't resolve 'http' in '/home/hash/speedtest/node_modules/speedtest-net'
ERROR in ./node_modules/agent-base/patch-core.js
Module not found: Error: Can't resolve 'https' in '/home/hash/speedtest/node_modules/agent-base'
ERROR in ./node_modules/speedtest-net/index.js
Module not found: Error: Can't resolve 'https' in '/home/hash/speedtest/node_modules/speedtest-net'
ERROR in ./node_modules/http-proxy-agent/index.js
Module not found: Error: Can't resolve 'net' in '/home/hash/speedtest/node_modules/http-proxy-agent'
ERROR in ./node_modules/https-proxy-agent/index.js
Module not found: Error: Can't resolve 'net' in '/home/hash/speedtest/node_modules/https-proxy-agent'
ERROR in ./node_modules/draftlog/lib/LineCountStream.js
Module not found: Error: Can't resolve 'stream' in '/home/hash/speedtest/node_modules/draftlog/lib'
ERROR in ./node_modules/xml2js/lib/parser.js
Module not found: Error: Can't resolve 'timers' in '/home/hash/speedtest/node_modules/xml2js/lib'
ERROR in ./node_modules/http-proxy-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/home/hash/speedtest/node_modules/http-proxy-agent'
ERROR in ./node_modules/https-proxy-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/home/hash/speedtest/node_modules/https-proxy-agent'

please is there any other way around to solve this problem and integrate this package with Angular 6...!!!

Fix speedtest.js link in package.json

Hello, nice work. I'm using meteor and it displays me an error:

Unable to resolve some modules "speedtest.js" in speedtest-net/package.json

That is why this package is not woking after my project deployment to nginx.
Could you please fix this problem (make a file or change a direction) ? It would be really nice. Thank you !

TypeError: process.hrtime is not a function

import * as SpeedTest from 'speedtest-net';

let testRun = SpeedTest({maxTime:5000});
testRun.on('testserver', server => {
console.dir(server);
});

run this in the browser, and it threw an error: TypeError: process.hrtime is not a function

error running speed-test: "Cannot read property 'settings' of null"

I get the following when I run speed-test. It appears to be a problem with speedtest-net, no?

$ speed-test
events.js:141
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read property 'settings' of null
    at gotServers (~/.nvm/versions/node/v5.0.0/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:465:22)
    at ~/.nvm/versions/node/v5.0.0/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:43:22
    at ~/.nvm/versions/node/v5.0.0/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:226:13
    at Parser.<anonymous> (~/.nvm/versions/node/v5.0.0/lib/node_modules/speed-test/node_modules/xml2js/lib/xml2js.js:483:18)
    at emitOne (events.js:77:13)
    at Parser.emit (events.js:169:7)
    at Parser.exports.Parser.Parser.parseString (~/.nvm/versions/node/v5.0.0/lib/node_modules/speed-test/node_modules/xml2js/lib/xml2js.js:493:16)
    at Parser.parseString (~/.nvm/versions/node/v5.0.0/lib/node_modules/speed-test/node_modules/xml2js/lib/xml2js.js:7:59)
    at exports.parseString (~/.nvm/versions/node/v5.0.0/lib/node_modules/speed-test/node_modules/xml2js/lib/xml2js.js:534:19)
    at ~/.nvm/versions/node/v5.0.0/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:224:9

Improve error message when servers cannot be fetched

The current error is not very helpful for users.

TypeError: Cannot read property 'settings' of null
    at gotServers (/home/travis/build/sindresorhus/speed-test/node_modules/speedtest-net/index.js:525:20)
    at /home/travis/build/sindresorhus/speed-test/node_modules/speedtest-net/index.js:48:16
    at /home/travis/build/sindresorhus/speed-test/node_modules/speedtest-net/index.js:241:7
    at Parser.<anonymous> (/home/travis/build/sindresorhus/speed-test/node_modules/xml2js/lib/xml2js.js:489:18)
    at emitOne (events.js:96:13)
    at Parser.emit (events.js:188:7)
    at Parser.exports.Parser.Parser.parseString (/home/travis/build/sindresorhus/speed-test/node_modules/xml2js/lib/xml2js.js:499:16)
    at Parser.parseString (/home/travis/build/sindresorhus/speed-test/node_modules/xml2js/lib/xml2js.js:7:59)
    at exports.parseString (/home/travis/build/sindresorhus/speed-test/node_modules/xml2js/lib/xml2js.js:540:19)
    at /home/travis/build/sindresorhus/speed-test/node_modules/speedtest-net/index.js:239:5

Related issue: sindresorhus/speed-test#27

Possible to manually make the ping request?

Hello,

I'm writing a snippet of code in client (browser) to get the download and upload speed from NodeJS. For now, I'm getting those speeds upon initializing speedtest module in server (Node). However, I'm finding a way to make a request from client to see (log) the speed. Is it possible to manually call / initiate the request?

Your response would help me a lot.

Thanks in advance,
Nathan

Can't get library to run test.

Hola!

Im having a hard time getting this library to work. This code from the homepage just sits there forever and will never finish:

  var speedTest=require('speedtest-net');

  test=speedTest({maxTime:5000});

  test.on('data',function(data){
    console.dir(data);
  });

  test.on('error',function(err){
    console.error(err);
  });

And this code:

var speedTest=require('speedtest-net');


speedTest.visual({maxTime:1000,log:true,maxServers:4},function(err,data){
  console.log(data);
});

Outputs this:

Testing from 70.112.1.161 at Time Warner Cable, expected dl: 2.59MB/s, expected ul: 0.32MB/s

And never finishes.

Not sure what the issue is. Is there anything I can run to help? I tried logging more events and it gets the full list of servers, but never the best servers.

Thanks!

`maxTime` does not have any effect

My mocha tests have a timeout of 10 seconds. My maxTime is set to 5000. If I am not mistaken, this is a bug.

I'm willing to PR to write tests for this project.

http.request does not function when browserify.

Hello!

Great work on this.. Download and upload are workin using node on a mac. however when I browserified it and moved to a cordova project, I found that it gets stuck when doing the http.request (upload speed test).The download test works great on cordova. Any insights on this issue?

Cannot read property 'servers' of undefined

Since this morning, my application gets the following error when performing a speediest:

TypeError: Cannot read property 'servers' of undefined
    at gotServers (/myproject/node_modules/speedtest-net/index.js:522:29)
    at /myproject/node_modules/speedtest-net/index.js:48:16
    at /myproject/node_modules/speedtest-net/index.js:238:7
    at Parser.<anonymous> (/myproject/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:489:18)
    at emitOne (events.js:77:13)
    at Parser.emit (events.js:169:7)
    at Object.onclosetag (/myproject/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:447:26)
    at emit (/myproject/node_modules/speedtest-net/node_modules/xml2js/node_modules/sax/lib/sax.js:640:35)
    at emitNode (/myproject/node_modules/speedtest-net/node_modules/xml2js/node_modules/sax/lib/sax.js:645:5)
    at closeTag (/myproject/node_modules/speedtest-net/node_modules/xml2js/node_modules/sax/lib/sax.js:905:7)
    at Object.write (/myproject/node_modules/speedtest-net/node_modules/xml2js/node_modules/sax/lib/sax.js:1449:13)
    at Parser.exports.Parser.Parser.parseString (/myproject/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:508:31)
    at Parser.parseString (/myproject/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:7:59)
    at exports.parseString (/myproject/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:540:19)
    at /myproject/node_modules/speedtest-net/index.js:236:5
    at /myproject/node_modules/speedtest-net/index.js:48:16
    at IncomingMessage.<anonymous> (/myproject/node_modules/speedtest-net/index.js:110:7)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
    at doNTCallback2 (node.js:441:9)
    at process._tickDomainCallback (node.js:396:17)
[root@foobar myproject]# vim /myproject/libs/Main.js

Proxy Error: Unexpected close tag

Hello,

I am trying to use the proxy feature, and I get an unexpected close tag anyway I run it.

I have tried speedtest-net --proxy "http://example.com:80"

I have also tried doing it directly in the code using

var test = speedTest({maxTime: 5000, proxy : "http://example.com:80"});

The error is as follows:

Error: Unexpected close tag
Line: 109
Column: 7
Char: >
    at error (/speedtest/node_modules/sax/lib/sax.js:651:10)
    at strictFail (/speedtest/node_modules/sax/lib/sax.js:677:7)
    at closeTag (/speedtest/node_modules/sax/lib/sax.js:871:9)
    at SAXParser.write (/speedtest/node_modules/sax/lib/sax.js:1436:13)
    at Parser.exports.Parser.Parser.parseString (/speedtest/node_modules/xml2js/lib/parser.js:322:31)
    at Parser.parseString (/speedtest/node_modules/xml2js/lib/parser.js:5:59)
    at exports.parseString (/speedtest/node_modules/xml2js/lib/parser.js:354:19)
    at /speedtest/node_modules/speedtest-net/index.js:299:5
    at /speedtest/node_modules/speedtest-net/index.js:107:16
    at IncomingMessage.<anonymous> (/speedtest/node_modules/speedtest-net/index.js:175:7)

Weird Results since 1/25 ~2:30pm EST

I wrote a tool around this (very nice) package and noticed this morning that it's reporting strange values starting at the time mentioned above. Is it possible that the scale of the throughput has changed on the provider side?

image

Thanks!

How to execute the script and send values into html?

Hello,i am new to Nodejs, so i am finding out how can i execute the script from html page.
Like this: push the button to run the script
I need to pass the results of the scipt to html page.
And is it even possible, or is this works only on server side?
Thank you

Is this legit?

Hi Guys, is legit to use speedtest servers as source for this?

'speed' variable maybe wrong in the documentation

Hi, all!

I made a simply CLI for study purposes and I notice something that maybe it's wrong in the documentation.

Documentation

st.on('downloadspeedprogress', speed => {
  console.log('Download: ' + (speed / 1000).toFixed(2) + ' kB/s')
})

dividing the speed by 1000 always outputs a number like 0.01 kB/s

What I did

st.on('downloadspeedprogress', speed => {
  console.log('Download: ' + (speed * 100).toFixed(2) + ' kB/s')
})

so, after some tries I noticed that if I multiply the speed by 100, it outputs the right result, like 999.99 kB/s

Is this an error or I'm doing something wrong? maybe I didn't understand something there...

speedtest-net no license field

npm WARN [email protected] No license field.
localhost:speedtest.net-master yiji.liu$ npm install --save speedtest-net
npm ERR! Darwin 17.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--save" "speedtest-net"
npm ERR! node v8.4.0
npm ERR! npm v3.10.9
npm ERR! code ENOSELF

npm ERR! Refusing to install speedtest-net as a dependency of itself
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! https://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request:
npm ERR! /Users/yiji.liu/lyj/Demo/speedtest.net-master/npm-debug.log
localhost:speedtest.net-master yiji.liu$

upload test doesn't work on Linux

I'm running Node 0.12.4 on OS X 10.10 and Fedora 22, and OS X is reporting somewhat believable upload numbers, but Fedora is reporting about 4Gbps (way too high, as if it is instantly assuming that all the data to be written was already written).

Fix handling of 413 upload errors

#11 talks about speed measuring issues. Some of the issues are simply related to speedtest.net having complex data massaging and this may never be fixed.

However, as #37 addresses, when a large upload payload is sent, servers may reject said payload with a 413 Request Entity Too Large. This happens before the payload is sent. #37 implements a stopgap measure that prevents counting data that we didn't push into the network stack yet, but it still counts data that was passed over to the node http module but possibly not yet sent. Even if it were sent, it may be stuck in the Internets somewhere, which is what we're trying to measure.

The best course of action is to not count a 413 at all, and to prevent the payload from getting bigger than allowed again. Also, possibly prevent any attempt to send data over a size that's known to cause issues. We could probe all servers to find their maximums, for instance.

PRs welcome.

No network kills test (no problem), however kills node too

Hi,

(Thanks for this plugin, it's an awesome job).

I'll have a look at this myself and try to fix, will do a pull request when I can find a solution, however any pointers would be appreciated.

I do check for connectivity before running the test, however if the network connection fails during the test, the error kills the whole app rather than returning an error.

I'll probably do an error check within the gotServers() function.. I haven't followed the code through properly yet so this may be way off.

So, just letting you know I guess :-)

Best,

J

/Users/jamesgray/Sites/MOJ/sh-uptime/node_modules/speedtest-net/index.js:440
var s=servers.settings.servers[0].server;
^
TypeError: Cannot read property 'settings' of null
at gotServers (/Users/jamesgray/Sites/MOJ/sh-uptime/node_modules/speedtest-net/index.js:440:22)
at /Users/jamesgray/Sites/MOJ/sh-uptime/node_modules/speedtest-net/index.js:43:22
at /Users/jamesgray/Sites/MOJ/sh-uptime/node_modules/speedtest-net/index.js:226:13
at Parser. (/Users/jamesgray/Sites/MOJ/sh-uptime/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:432:18)
at Parser.emit (events.js:107:17)
at Parser.exports.Parser.Parser.parseString (/Users/jamesgray/Sites/MOJ/sh-uptime/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:441:14)
at Parser.parseString (/Users/jamesgray/Sites/MOJ/sh-uptime/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:6:59)
at exports.parseString (/Users/jamesgray/Sites/MOJ/sh-uptime/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:483:19)
at /Users/jamesgray/Sites/MOJ/sh-uptime/node_modules/speedtest-net/index.js:224:9
at /Users/jamesgray/Sites/MOJ/sh-uptime/node_modules/speedtest-net/index.js:43:22

Cannot read property 'servers' of undefined

events.js:160
throw er; // Unhandled 'error' event
^

TypeError: Cannot read property 'servers' of undefined
at gotServers (/home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:550:29)
at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:48:16
at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:241:7
at Parser. (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/xml2js.js:489:18)
at emitOne (events.js:96:13)
at Parser.emit (events.js:188:7)
at Object.onclosetag (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/xml2js.js:447:26)
at emit (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:640:35)
at emitNode (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:645:5)
at closeTag (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:905:7)
at Object.write (/home/abc/Desktop/test/speedNodejs/node_modules/sax/lib/sax.js:1452:13)
at Parser.exports.Parser.Parser.parseString (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/xml2js.js:508:31)
at Parser.parseString (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/xml2js.js:7:59)
at exports.parseString (/home/abc/Desktop/test/speedNodejs/node_modules/xml2js/lib/xml2js.js:540:19)
at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:239:5
at /home/abc/Desktop/test/speedNodejs/node_modules/speedtest-net/index.js:48:16

"socket hang up" when using Proxy

I am using a http proxy with speedtest-net like below:

var speedTest = require('speedtest-net');

speedTest.visual({maxTime: 15000, proxy: "http://127.0.0.1:7890"}, (err, data) => {
  console.dir(err, data);
});

Then got an error:

{ Error: socket hang up
    at createHangUpError (_http_client.js:322:15)
    at Socket.socketOnEnd (_http_client.js:425:23)
    at Socket.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at process._tickCallback (internal/process/next_tick.js:63:19) code: 'ECONNRESET' }

Upload-Only Testing

It'd be cool if we could get upload-only tests! How much work do you think it would be to modify the library to support options for which metrics you care about? I noticed the progression of testing is hardcoded in.

Add option to bind speedtest to run on specific interface "--source SOURCE"

where SOURCE = eth0/wlan0/etc. or IP address

We are contemplating migrating an existing project to nodejs where we'd need to be able to run the speedtest over multiple different interfaces (basically checking speedtest on wlan0 and eth0)

Similar to functionality on https://github.com/sivel/speedtest-cli

It would be preferable to be able to specify interface name (eth0) instead of the IP address (could use something like https://www.npmjs.com/package/network)

var speedTest = require('speedtest-net');
var test = speedTest({maxTime: 5000, source: "eth0"});

Should include interface in output also {interface: "eth0"} or {interface: "192.168.1.10"}

All tests should pass.

Would like your email

I am interested in discussing some changes to your code to allow this to work with pingtest.net. This would make the data very useful to VoIP implementations. I would willing to pay you for the changes. I can be reached at chris -a-t- intutivetechnology -d-o-t- com

[Question] Possible to extract client lib for in-browser

Sorry if this is a silly question, but took a quick look at code and it wasn't immediately obvious to me: with your deep understanding of how speedtest.net works, would be be possible for someone to split this tool into the cli portion and a pure js library that could be run in-browser (ie. no nodejs dep)

Is it possible to use this library with React Native?

i'm trying to use this speedtest library with React Native to build a mobile app. I specifically want to find the upload and download speed from a certain server and I know that with this library you can do so by inserting the server's id. However, when I try to integrate this into React Native, I can't seem to call the speedTest method and get a TypeError:

Possible Unhandled Promise Rejection (id: 0):
TypeError: Network request failed
TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:15825:18)
at XMLHttpRequest.dispatchEvent (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:17902:39)
at XMLHttpRequest.setReadyState (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:17657:20)
at XMLHttpRequest.__didCompleteResponse (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:17484:16)
at blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:17594:47
at RCTDeviceEventEmitter.emit (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:3480:37)
at MessageQueue.__callFunction (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:2386:44)
at blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:2156:17
at MessageQueue.__guardSafe (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:2348:11)
at MessageQueue.callFunctionReturnFlushedQueue (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:2155:14)

Possible Unhandled Promise Rejection (id: 1):
TypeError: One of the sources for assign has an enumerable key on the prototype chain. Are you trying to assign a prototype property? We don't allow it, as this is an edge case that we do not support. This error is a performance optimization and not spec compliant.
TypeError: One of the sources for assign has an enumerable key on the prototype chain. Are you trying to assign a prototype property? We don't allow it, as this is an edge case that we do not support. This error is a performance optimization and not spec compliant.
at Object.assign (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:331:19)
at Object.request (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:83858:23)
at Object.https.get (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:83871:25)
at getHttp (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:87427:16)
at getXML (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:87550:11)
at nextServer (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:87827:13)
at gotServers (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:87833:29)
at blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:87386:24
at module.exports. (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:87551:29)
at module.exports. (blob:http://localhost:8081/d1e6973c-7f4c-45aa-8bf6-19e7fcddb886:87386:24)

Here is how my two lines of code looks like:

const speedTest = require('./speedtest');
const test = speedTest({maxTime: 5000, serverId : "7334"});

I had to do a workaround to import the node module in React Native which works perfectly. I don't get an error when I do require, but right when I call the speedTest is when I get the above error. Does anyone have any thoughts or two cents with this issue?

testserver data does not have same properties as data event

Hi

The testserver event returns an object with properties of the server that is being used for testing. The data event does also return those values, but with different property names.

Just to name a few:

testserver data
host url
location name
distance dist

I think it would be nice to make them both consistent and be sure both events have the same properties.

Unhandled 'error' event

Today, i got this error: it is the first time in months, seams that the server sent something not expected by the client software:

events.js:85
throw er; // Unhandled 'error' event
^
TypeError: Cannot read property 'settings' of null
at gotConfig (/var/lib/cloud9/node_modules/speedtest-net/index.js:510:20)
at lat1 (/var/lib/cloud9/node_modules/speedtest-net/index.js:48:16)
at /var/lib/cloud9/node_modules/speedtest-net/index.js:241:7
at Parser. (/var/lib/cloud9/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:489:18)
at Parser.emit (events.js:107:17)
at Parser.exports.Parser.Parser.parseString (/var/lib/cloud9/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:499:16)
at Parser.bind [as parseString] (/var/lib/cloud9/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:7:59)
at exports.parseString (/var/lib/cloud9/node_modules/speedtest-net/node_modules/xml2js/lib/xml2js.js:540:19)
at /var/lib/cloud9/node_modules/speedtest-net/index.js:239:5
at lat1 (/var/lib/cloud9/node_modules/speedtest-net/index.js:48:16)
at IncomingMessage. (/var/lib/cloud9/node_modules/speedtest-net/index.js:113:7)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)

Not working with the React JS

I'm trying to implement the module in React JS. But it not producing the desired results and specifically throwing the error in the console of " Failed to load http://www.speedtest.net/speedtest-config.php: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. "

And for more detailed error please check the screenshot.

React JS Env:

"dependencies": {
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-scripts": "2.0.4",
"speedtest-net": "^1.4.3"
}

speedtestreactissue

Receiving an error when running the speed-test command

speed-test

events.js:154
throw er; // Unhandled 'error' event
^
TypeError: Cannot read property 'settings' of null
at gotServers (/usr/local/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:522:20)
at /usr/local/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:48:16
at /usr/local/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:238:7
at Parser. (/usr/local/lib/node_modules/speed-test/node_modules/xml2js/lib/xml2js.js:484:18)
at emitOne (events.js:90:13)
at Parser.emit (events.js:182:7)
at Parser.exports.Parser.Parser.parseString (/usr/local/lib/node_modules/speed-test/node_modules/xml2js/lib/xml2js.js:494:16)
at Parser.parseString (/usr/local/lib/node_modules/speed-test/node_modules/xml2js/lib/xml2js.js:7:59)
at exports.parseString (/usr/local/lib/node_modules/speed-test/node_modules/xml2js/lib/xml2js.js:535:19)
at /usr/local/lib/node_modules/speed-test/node_modules/speedtest-net/index.js:236:5

Test Results

I am running this test on a raspberry pi 2m and my laptop, and the test results differ greatly than what I am seeing from my speedtest.net in a browser.

My browser speedtest gets ~ 40mbps for download and 50 Mbps upload (which is what we have here at the office)

When I run this script from the command line in linux and windows I get ~20Mbps download and ~30Mbps upload (I had to convert from bytes to bits as bytes is not a very useful measurement for these types of tests).

Also, when running the script it sometimes chooses a server over 100 miles away when there is a server less than 20 that it sometimes chooses. Is there a rhyme or reason to this?

Can you check to see if there is something in this script that is causing weird and unexpected results?

Thanks.

http.get hang without timeout

I know this might be a weird very particular situation but I have encountered that in the following environment (on my electron app) the http.get call never invokes the callback unless I set the timeout option.

  • OS: Ubuntu 14.04 (gnome-session-fallback)
  • node version: 6.15.1
  • electron version: 3.0.0
  • speedtest-net version: 1.4.3

It does not even time out, but behaves appropriately. If I do not set that option the http.get function does not invoke the callback nor throws an error.

The fix is to set the option just like below.

options.headers = options.headers || {};
options.headers['user-agent'] = options.headers['user-agent'] || 'Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.' + Math.trunc(Math.random() * 400 + 2704) + '.' + Math.trunc(Math.random() * 400 + 103) + ' Safari/537.36';

options.timeout = 20;
  
http.get(options, function(res) {
    if (res.statusCode === 302) {

Anyway. Just wanted to leave it somewhere. Any suggestions for the timeout value for the get operations?

Test server always China

Hello,

This package was working a ~couple weeks ago but now it can't get the ISP information and the test server is always China Mobile even if I use the option serverId and select an Australian server still forces to China Mobile.

System: MacOS 10.14.3
Node: v11.7.0 (installed from brew)
speedtest-net version: 1.4.3

Code

var speedTest = require('speedtest-net');
// Telstra Server ID
var test = speedTest({maxTime: 5000, serverId: '2628'});
 
test.on('data', data => {
  console.dir(data);
});
 
test.on('error', err => {
  console.error(err);
});

Output

{ speeds:
   { download: 1.284,
     upload: 1.768,
     originalDownload: 141373,
     originalUpload: 194016 },
  client:
   { lat: NaN,
     lon: NaN,
     isprating: NaN,
     rating: NaN,
     ispdlavg: NaN,
     ispulavg: NaN },
  server:
   { host: 'speedtest4.xj.chinamobile.com',
     lat: 81.3241,
     lon: 43.9168,
     location: 'Yili',
     country: 'China',
     cc: 'CN',
     sponsor: 'China Mobile Group XinJiang',
     distance: NaN,
     distanceMi: NaN,
     ping: 735.1,
     id: '17228' } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.