每当我运行此代码时,我都会收到一条错误消息csv.pipe is not a function
。
我认为可能与stdout中的回调有关?
var fs = require('fs');
var spawn = require('child_process').spawn;
var speedtest = spawn('speedtest-cli',['--json']);
var csv = require('csv-write-stream')
speedtest.stdout.on('data', function(data){
var dataObj = JSON.parse(data);
var down = (dataObj.download/1000000).toFixed(2);
var up = (dataObj.upload/1000000).toFixed(2);
csv.pipe(fs.createWriteStream('speed.csv',{flags: 'a'}));
csv.write([dataObj.timestamp,down,up]);
csv.end();
});
答案 0 :(得分:0)
var fs = require('fs');
var spawn = require('child_process').spawn;
var speedtest = spawn('speedtest-cli',['--json']);
var csvWriteStream = require('csv-write-stream');
var csv = csvWriteStream();//I added this string
speedtest.stdout.on('data', function(data){
var dataObj = JSON.parse(data);
var down = (dataObj.download/1000000).toFixed(2);
var up = (dataObj.upload/1000000).toFixed(2);
csv.pipe(fs.createWriteStream('speed.csv',{flags: 'a'}));
csv.write([dataObj.timestamp,down,up]);
csv.end();
});