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" })
  })
2
  • Have you imported the required npm package ? const csv = require('fast-csv'); Commented Feb 15, 2020 at 10:49
  • @RajithaWarusavitarana Yes without it node server is not getting started Commented Feb 15, 2020 at 11:56

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.