代码如下
const fs = require("fs");
const stringify = require("csv-stringify");
const data =[]
//创建转换流
const stringifier = stringify({
delimiter:',',
record_delimiter:"windows"
});
//有可读数据实逐行处理
stringifier.on("readable",()=>{
let row;
while(row=stringifier.read()){
data.push(row);
}
});
stringifier.on("finish",()=>{
fs.writeFile("newcsv.csv",data,(err)=>{
if(err){
return console.error(err);
}
});
});
stringifier.write(['root','x','0','root','/root','/bin/bash']);
stringifier.write(['zxp','x','10224','1024','/home/zxp','bin/bash']);
stringifier.end();
报错如下
node:internal/fs/utils:879
throw new ERR_INVALID_ARG_TYPE(
^
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Array
at Object.writeFile (node:fs:2106:5)
at Stringifier.<anonymous> (E:\工作区\第三次作业\test2.js:18:8)
at Stringifier.emit (node:events:394:28)
at finish (node:internal/streams/writable:750:10)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ERR_INVALID_ARG_TYPE'
}
求解决方案!