My team is trying to take questions by developers in a CSV and parse it to put into a database. Some developers have commas in their questions.
The format of the CSV is Question,Answer. For example, a row might be `Hi, how are you,good' or 'what is life?,42'
fs.createReadStream(file)
.pipe(createCsvParser())
.on("data", (row) => {
console.log(row);
questionSet.push(row); //appends row to questionSet array
})
.on("end", () => {
console.log("CSV file successfully processed");
});
This is our current code. Thank you for your help
Instead of writing your custom code. Consider using a CSV-Parse library. It is widely used and takes care of the situation you are describing. This is because the library uses CSV file headers to identify the data in rows.
After you install the library
The
questionSet
Array will have objects representing rows of your CSV with the situation you described being handled.