使用快速csv不读取csv文件 [英] Using fast-csv not reading csv file
本文介绍了使用快速csv不读取csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试先读取CSV文件,但出现一条错误消息:
I am trying to first read the CSV file, but I am getting an error saying:
TypeError:fs.createReadStream不是一个函数。
TypeError: fs.createReadStream is not a function.
我做错了吗?这是我的代码:
Am I doing something wrong? Here is my code:
fs.createReadStream('accounts.csv')
.pipe(csv())
.on('data', function (data) {
console.log(data);
})
.on('end', function () {
console.log('Read finished');
});
推荐答案
我意识到我的文件中没有文件项目,这就是它不阅读的原因,此外,我将代码更改为此。
I realized that i did not have the file inside my project, which is the reason it was not reading it, also, i changed my code to this.
const csv = require('csv-parser');
const fs = require('fs');
const fast = require('fast-csv');
fs.createReadStream('accounts.csv')
.pipe(csv())
.on('data', (row) => {
console.log(row);
})
.on('end', () => {
console.log('CSV file successfully processed');
这篇关于使用快速csv不读取csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文