2017-02-16 15 views
4

私はcsvファイルの変換行をjsonに変換する必要があります。私はcsvtojsonパッケージを使用し、魅力的に動作しますが、私のCSVファイルは約21.000.000行と非常に巨大です。 :(ノードjs JSON(大ファイル)へのCSV

マイノードアプリは、すべての行を処理することができない。

私のスニペット怒鳴るを参照してください。

csv({noheader:true, 
     delimiter:";", 
    workerNum: 4}) 
    .fromFile(csvFilePath) 
    .on('json',(jsonObj, rowIndex)=>{ 
     var TN = jsonObj.field1; 
     var cod_op = jsonObj.field2; 
     var msisdn = TN.toString(); 

    //UP TO FIREBASE HERE!!! 

     noticia.child(msisdn).set(cod_op); 
     console.log(TN + ' ' + rowIndex); 



    }) 
    .on('done',(error)=>{ 
     console.log() 
    }) 

答えて

2

私はここでcsv-stream module

で私の自己によって解決snippset

var options = { 
    delimiter : ';', // default is , 
    endLine : '\n', // default is \n, 
    columns : ['VERSION_ID', 'TN','RN1','DATA','OPERACAO','CNL','EOT'], // by default read the first line and use values found as columns 
    columnOffset : 7, // default is 0 
    escapeChar : '"', // default is an empty string 
    enclosedChar : '"' // default is an empty string 
} 

var csvStream = csv.createStream(options); 
i = 0 
request('http://yourhugefile.csv').pipe(csvStream) 
    .on('error',function(err){ 
     console.error(err); 
    }) 
    .on('data',function(data){ 
     // outputs an object containing a set of key/value pair representing a line found in the csv file. 
     //console.log(data); 
    }) 
    .on('column',function(key,value){ 
     if(key == 'TN' || key == 'RN1') 
      firebaseUpload(value); 
     // outputs the column name associated with the value found 
     //console.log('#' + key + ' = ' + value); 
    }) 
です
関連する問題