4

I'm using fast-csv to read my csv file but it gives me error like this

UnhandledPromiseRejectionWarning: TypeError: csv.fromPath is not a function

Here is my code:

const fileRows = [];
console.log("req.file.path",req.file.path)
// open uploaded file
csv.fromPath(req.file.path)
  .on("data", function (data) {
    fileRows.push(data); // push each row
  })
  .on("end", function () {
    console.log(fileRows);
    //fs.unlinkSync(req.file.path);   // remove temp file

    const validationError = validateCsvData(fileRows);
    if (validationError) {
      return res.status(403).json({ error: validationError });
    }
    //else process "fileRows" and respond
    return res.json({ message: "valid csv" })
  })
Harsh Patel
  • 6,334
  • 10
  • 40
  • 73

1 Answers1

11

for 'fast-csv' version >= 3.0.0 :- fromPath deprecated in favor of parseFile i.e. csv.fromPath() changed to csv.parseFile()

for more detail visit : https://github.com/C2FO/fast-csv/blob/master/History.md

mjp
  • 131
  • 4