更新时间:2022-05-27 22:05:57
您可以使用节点模块'csv-parse'.
You can use node module 'csv-parse'.
看看下面的代码.
var csvParser = require('csv-parse');
fs.readFile(filePath, {
encoding: 'utf-8'
}, function(err, csvData) {
if (err) {
console.log(err);
}
csvParser(csvData, {
delimiter: ','
}, function(err, data) {
if (err) {
console.log(err);
} else {
console.log(data);
}
});
});
此处filePath是csv文件的路径,分隔符将根据您的文件.它是分隔csv文件中字段的字符(可以是',','.'等).
Here filePath is path of the csv file and the delimiter will be as per your file. It is the character that separates fields in csv file(can be ',', '.', etc).