0

What i would like to to is import a csv file in my program knowing it's path.

For example if the path to the csv is C:/Users/User/example.csv I would like to somehow load this in my program, something like:

let MY_CSV_FILE =CSV_LOAD("C:/Users/User/example.csv")

I don't care about writing to it or reading from it, just loading it.

How could this be done in javascript?

J.F.
  • 13,927
  • 9
  • 27
  • 65
lemourios
  • 17
  • 1
  • Does [this](https://stackoverflow.com/q/7431268/13464279) answer your question? – J.F. Jan 14 '21 at 16:48
  • Does this answer your question? [How to read data From \*.CSV file using javascript?](https://stackoverflow.com/questions/7431268/how-to-read-data-from-csv-file-using-javascript) – 0stone0 Jan 14 '21 at 16:49

1 Answers1

0

Based on the tags you selected, I am assuming you want to read your CSV data into your Node app. You need a package like node-csv. You can then use csv-parse to load you CSV data.

Install it first

$ npm install node-csv

And then read your file like this:

const fs = require('fs'); 
const parse = require('csv-parse');
const parser = parse({columns: true}, (err, records) => {
    console.log(records);
});

fs.createReadStream("C:/Users/User/example.csv").pipe(parser);
codemonkey
  • 7,325
  • 5
  • 22
  • 36