我一直在开发一个在读取 csv 时输出 xml 的项目,我使用 fs.createReadStream()
方法读取 csv 文件,但一段时间后,终端崩溃了。
我明白了
C:\Users\username\Documents\Programming\Node Projects\DAE Parser\main.js:13
row["Value"].includes("tri") ||
^
TypeError: Cannot read property 'includes' of undefined
它不会读取整个文件。
这就是我正在做的事情
fs.createReadStream("test.csv")
.pipe(csv())
.on("data", row => {
if (
row["Value"].includes("tri") ||
row["Value"].includes("vt") ||
row["Value"].includes("vx") ||
row["Value"].includes("vn")
) {
console.log(row)
}
})
最佳答案
您的row["Value"]
未定义,您可以添加一个条件来检查它是否为假
fs.createReadStream("test.csv")
.pipe(csv())
.on("data", row => {
if (row["Value"] && (
row["Value"].includes("tri") ||
row["Value"].includes("vt") ||
row["Value"].includes("vx") ||
row["Value"].includes("vn")
)) {
console.log(row)
}
})
关于javascript - NodeJS 在引导 csv 文件一段时间后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58694588/