@@ -0,0 +1,1647 @@
+require('dotenv').config();%0Aconst fs = require('fs');%0Aconst speedTest = require('speedtest-net');%0Aconst moment = require('moment');%0A%0A// time test was ran%0Aconst timestamp = new Date().getTime();%0A// CSV file name%0Aconst fileName = moment(timestamp).format(process.env.MOMENT_FORMAT) + process.env.FILE_NAME;%0A// Where CSV files get stored%0Aconst filePath = %60$%7Bprocess.env.REPORT_PATH%7D/$%7BfileName%7D%60;%0A%0A// Run test%0Aconst runTest = speedTest(%7BmaxTime: process.env.MAXTIME%7D);%0A%0A/**%0A * When data received data write to csv or create new csv%0A * @param  %7BObject%7D data Response from speed test%0A */%0Aconst onData = function(data) %7B%0A%09let download = data.speeds.download;%0A%09let upload = data.speeds.upload;%0A%09let csvLine = %60$%7Btimestamp%7D,$%7Bdownload%7D,$%7Bupload%7D%5Cn%60;%0A%09%0A%09fs.stat(filePath, (err, stats)=%3E%7B%0A%09%09if (!!err) %7B%0A%09%09%09WriteNew(csvLine)%0A%09%09%7D else %7B%0A%09%09%09WriteTo(csvLine)%0A%09%09%7D%0A%09%7D)%0A%7D%0A/**%0A * Simple error Loggin function%0A * @param  %7BString%7D err Descrive error%0A */%0Aconst onError = function (err) %7B%0A%09console.error(err);%0A%09process.exit(1);%0A%7D%0A%0A/**%0A * Append test data to existing file%0A * @param %7BString%7D csvLine timestamp,download,upload values%0A */%0Aconst WriteTo = function (csvLine) %7B%0A%09console.log(WriteTo)%0A%09fs.appendFile(filePath, csvLine, onError);%0A%09process.exit(0);%0A%7D%0A%0A/**%0A * Create new scv file with header and values%0A * @param %7BString%7D csvLine timestamp,download,upload values%0A */%0Aconst WriteNew = function (csvLine) %7B%0A%09console.log(WriteNew)%0A%09let csvData = 'timestamp,download,upload%5Cn';%0A%09csvData += csvLine;%0A%09fs.writeFile(filePath, csvData, onError);%0A%09process.exit(0);%0A%7D%0A%0A// Received data call back%0ArunTest.on('data', onData);%0A// error callback%0ArunTest.on('error', onError);

create speed test script