Using FS to read in a CSV
suggest changefs is the file system API. readFile reads data.csv as UTF-8. The callback splits the text on line breaks. If err is set, data is undefined and data.split throws. Check err before using data.
This assumes you have a file named data.csv in the same folder.
'use strict'
const fs = require('fs');
fs.readFile('data.csv', 'utf8', function (err, data) {
var dataArray = data.split(/\r?\n/);
console.log(dataArray);
});
You can now use the array like any other to do work on it.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents