As the title says, I'm loading (or at least trying to) two CSV files and store them in two separate arrays. What I have so far worked, but it isn't the most elegant, no efficient solution.
The end goal is to read in two CSV files and run comparisons on them both - that's why the separating them is important.
Note - I use the csv-parser
library, but am open to different solutions.
const express = require("express");
const parse = require("csv-parser");
const fs = require("fs");
const app = express();
const port = 3000;
var CSVOne = [];
var CSVTwo = [];
fs.createReadStream("public/activity.csv")
.pipe(parse())
.on("data", data => CSVOne.push(data))
.on("end", () => {
sender = CSVOne.map(d => {
return {
email: d.Sender
};
});
fs.createReadStream("public/groups.csv")
.pipe(parse())
.on("data", dataTwo => CSVTwo.push(dataTwo))
.on("end", () => {
one = CSVTwo.map(d => {
return {
clinic: d.one
};
});
console.log(sender);
console.log(one);
});
});
app.listen(port, function() {
console.log("Server has started");
});