2 |
3 |
Internet speed report in your terminal!
5 | 6 |
12 | 13 |
21 |
22 |
23 | ## :wave: Thanks
24 |
25 | - [speedtest-net](https://github.com/ddsol/speedtest.net) for providing fast & simple API!
26 |
27 | ## :clipboard: License
28 |
29 | MIT © [Antoni Kepinski](https://akepinski.me)
30 |
--------------------------------------------------------------------------------
/cli.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | 'use strict';
4 |
5 | const chalk = require('chalk');
6 | const meow = require('meow');
7 | const speedTest = require('speedtest-net');
8 | const Table = require('cli-table3');
9 | const ora = require('ora');
10 |
11 | const spinner = ora();
12 |
13 | // Help message
14 | meow(`
15 | Usage:
16 | Just run ${chalk.green.bold('speedo')} to start a speed test!
17 |
18 | Powered by ${chalk.cyan('speedtest.net')}
19 | `);
20 |
21 | // Speed test configuration
22 | const st = speedTest({maxTime: 5250});
23 |
24 | // Output in MB/s
25 | st.on('data', async data => {
26 | const download = await (data.speeds.download * 0.125).toFixed(2);
27 | const upload = await (data.speeds.upload * 0.125).toFixed(2);
28 |
29 | // Table
30 | const table = new Table({
31 | head: [`${chalk.red.bold('Type:')}`, `${chalk.red.bold('Speed:')}`],
32 | colWidths: [25, 25]
33 | });
34 |
35 | table.push(
36 | [`${chalk.cyan('Download')}`, `${chalk.green(`${download}`)} MB/s`],
37 | [`${chalk.cyan('Upload')}`, `${chalk.green(`${upload}`)} MB/s`],
38 | [`${chalk.cyan('Latency')}`, `${chalk.green(`${data.server.ping}`)} ms`]
39 | );
40 |
41 | // Print the final report table
42 | spinner.succeed('Done! Here is your speed report:\n');
43 | console.log(table.toString());
44 | });
45 |
46 | // Download and Upload speed log
47 | st.on('downloadspeedprogress', async speed => {
48 | spinner.text = `Testing download speed... ${chalk.green(`${(await speed * 0.125).toFixed(2)} MB/s`)}`;
49 | spinner.start();
50 | });
51 | st.on('uploadspeedprogress', async speed => {
52 | spinner.text = `Testing upload speed... ${chalk.yellow(`${(await speed * 0.125).toFixed(2)} MB/s`)}`;
53 | spinner.start();
54 | });
55 |
56 | // Handle the error
57 | st.on('error', err => {
58 | /* istanbul ignore next */
59 | if (err.code === 'ENOTFOUND') {
60 | console.error(chalk.red.bold('Unable to connect to the server :('));
61 | }
62 | });
63 |
--------------------------------------------------------------------------------
/speedo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------