JS

HOW TO READ CSV FILES IN NODEJS

READ CSV INTO STRING const fs = require("fs"); var data = fs.readFileSync("FILE.CSV", "utf8");

READ INTO STRING

01

SPLIT ROWS data = data.split("\r\n");   SPLIT COLUMNS for (let i of data) {   data[i] = data[i].split(","); }

FILE STREAM cosnt fs = require("fs"),            rl = require("readline"); var stream =          fs.createReadStream("FILE.CSV"),       reader = rl.createInterface({ input:        stream });

READ LINE BY LINE

02

READ LINE-BY-LINE var arr = []; reader.on("line", (row) =>   { arr.push(row.split(",")) });