[英]bare bone csv-parse won't parse anything
使用下面的代碼,我希望看到正在打印的記錄。 但我得到無線電沉默。 沒有錯誤或任何記錄被打印。
CSV 文件內容並位於與 index.js 相同的文件夾中
userId,prefChannel
1,push.pref
2,email.pref
3,email.pref
4,email.pref
5,push.pref
6,push.pref
7,email.pref
8,push.pref
9,email.pref
10,push.pref
csv 版本為:
"dependencies": {
"csv": "^6.2.0"
}
index.js 代碼:
const fs = require("fs");
const { parse } = require('csv-parse');
async function readRecordsFromCSV() {
const cvsFileName = (__dirname + SETTINGS.filePath);
console.info(chalk.green(`Streaming file: ${cvsFileName}`));
// read csv file
const parser = parse({delimiter: ','}, function(err, data){
console.log(data);
console.log(err);
});
fs.createReadStream(cvsFileName).pipe(parser);
}
// driver code:
// Run the script
; (async function () {
// read and transform all items from csv file
const newPrefs_1 = await transformPreferenceRecordsFromCSV();
})()
我將通過傳入文件名來啟動腳本,這是我的測試 output:
**Streaming file: {correct file path}/.../bq-results-10-records-test.csv**
有問題的代碼實際上有效。 我的本地在驅動程序代碼的末尾有這個,導致它提前終止。
process.exit(1);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.