为什么未在nodejs中触发头事件

问题描述 投票:0回答:1

我在其中一个应用程序中有此代码。

 const readStream= fs.createReadStream('xlsx file path here');
        readStream.on('header', (header) => {
            console.log('header event');
           console.log(header);
        })
        .on('data',  function(file) {
            console.log('data event');  
            
        });

此代码在其他应用程序中可以正常工作,但是当我将相同的代码复制到另一个应用程序中时,不会触发“标头”事件。但是“数据”事件正在触发。尝试使用相同的xlsx文件。

node.js stream
1个回答
0
投票

我认为您对库,内置流(例如fs.createReadStream没有标题事件)感到困惑。

csv-parser最有可能

fs.createReadStream('data.csv')
  .pipe(csv())
  .on('headers', (headers) => {
    console.log(`First header: ${headers[0]}`)
  })
© www.soinside.com 2019 - 2024. All rights reserved.