1

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');
    });
4
  • do you have const fs = require('fs') or somthing similar in your js file? Commented Mar 6, 2019 at 19:55
  • yes i do. is the csv file need to be in a specific folder? Commented Mar 6, 2019 at 19:59
  • Yes, if you don't specify a path node will assume it's in the current directory, however that wouldn't be the cause of your error. if fs.createReadStream istn' a function it seems like you haven't imported it correctly Commented Mar 6, 2019 at 20:36
  • If the file was in the wrong place your error would be along the lines of can't find <file> Commented Mar 6, 2019 at 20:37

1 Answer 1

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.