Parsing a CSV file using NodeJS

后端 未结 16 2376
执笔经年
执笔经年 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:47

    this is my solution to get csv file from external url

    const parse = require( 'csv-parse/lib/sync' );
    const axios = require( 'axios' );
    const readCSV = ( module.exports.readCSV = async ( path ) => {
    try {
       const res = await axios( { url: path, method: 'GET', responseType: 'blob' } );
       let records = parse( res.data, {
          columns: true,
          skip_empty_lines: true
        } );
    
        return records;
     } catch ( e ) {
       console.log( 'err' );
     }
    
    } );
    readCSV('https://urltofilecsv');
    

提交回复
热议问题