Importing CSV with Nodejs Problems with CSV first column

Asked

Viewed 16 times

0

Good evening guys, someone has already had the problem in importing a CSV where the first column of the file comes as Undefined?

// import_customers_service

import_customers_service('./data_files/customers_service.csv');

function import_customers_service(filename){

    let stream = fs.createReadStream(filename);
    let parser = csv.parse({
        delimiter: ',',
        columns: true
    });

    let transform = csv.transform(function(row) {
        
        let resultObj = {
            id: row['id'],
            name: row['name']
        }

        console.log(resultObj);

    });

    stream.pipe(parser).pipe(transform)

}

Aquivo CSV

id,name
1,Yes
2,No
3,No phone service

Upshot:

{ id: undefined, name: 'Yes' }
{ id: undefined, name: 'No' }
{ id: undefined, name: 'No phone service' }

Has anyone ever seen anything about that mistake?

Hug

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.