Jamgreen
Jamgreen

Reputation: 11039

Parse csv file in Meteor

How can I import and interpret csv files in Meteor?

I have a simple csv file

name, address, age, (...)
==================
A, A, 41, (...)
B, A, 41, (...)
C, A, 41, (...)
D, A, 41, (...)
E, A, 41, (...)
F, A, 41, (...)
(...)

and I just want to loop through each row and insert some docs in some collections depending on the values in the different columns in each row.

I guess I can do something like

var filename = "my_file.csv";
var csvFile = csv.readFile(filename);

for (var row in csvFile) {
    if (row[0] === "D") {
        Collection.insert(...);
    } else if (row[1] === "E") {
        ...
    }
}

but I don't know how to parse the file when using Meteor/javascript.

Upvotes: 1

Views: 632

Answers (1)

Alan B
Alan B

Reputation: 4288

You probably need a CSV library like Papa Parse

Upvotes: 1

Related Questions