Parsing a CSV file using NodeJS

后端 未结 16 2363
执笔经年
执笔经年 2020-11-27 12:15

With nodejs I want to parse a .csv file of 10000 records and do some operation on each row. I tried using http://www.adaltas.com/projects/node-csv. I couldnt get this to pau

16条回答
  •  时光说笑
    2020-11-27 12:49

    In order to pause the streaming in fast-csv you can do the following:

    let csvstream = csv.fromPath(filePath, { headers: true })
        .on("data", function (row) {
            csvstream.pause();
            // do some heavy work
            // when done resume the stream
            csvstream.resume();
        })
        .on("end", function () {
            console.log("We are done!")
        })
        .on("error", function (error) {
            console.log(error)
        });
    

提交回复
热议问题