Using fast-csv not reading csv file

老子叫甜甜 提交于 2020-06-28 09:03:48

问题


I am trying to first read the CSV file, but I am getting an error saying:

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');
    });

回答1:


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');


来源:https://stackoverflow.com/questions/55031113/using-fast-csv-not-reading-csv-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!