类型错误:csv.fromPath 不是函数

Har*_*tel 2 csv node.js express fast-csv

我正在使用fast-csv读取我的 csv 文件,但它给了我这样的错误

UnhandledPromiseRejectionWarning: TypeError: csv.fromPath is not a function

这是我的代码:

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" })
  })
Run Code Online (Sandbox Code Playgroud)

小智 8

对于“fast-csv”版本>= 3.0.0 :- fromPath 已弃用而支持 parseFile,即 csv.fromPath() 更改为 csv.parseFile()

更多详情请访问:https : //github.com/C2FO/fast-csv/blob/master/History.md