Skip to content

First property inaccsesible of objects parsed by csv-parse

I am parsing a csv file with following contents using csv-parse


However, on the objects returned it isn’t possible to access the property created from the first column userID.

Here is my code —

async function main(){
    let systemIDs = await getSystemIds('./systems.csv');     
    console.log(`Scanning data for ${systemIDs.length} systems..`);

    console.log(systemIDs[0].userID); // This prints undefined 
    console.log(systemIDs[0].sysID);  // This prints the correct value

async function getSystemIds(path){
    let ids= [];
    await new Promise ((resolve,reject)=>{        
        const csvParser = csvParse({columns:true, skip_empty_lines: true});
        .on('readable', ()=>{
            let record ;            
            while(record = {
    return ids;

Output –

Scanning data for 2 systems..
{ 'userID': '20', sysID: '50' } 
undefined  // <== The Problem

I notice the first column key userID has single quotes around it in the console output where as sysID doesn’t. But don’t know what is causing them.


Figured it out myself in the end…

I needed the BOM option. The documentation states it should be set to true for UTF-8 files. But it defaults to false.

Excel by default generates csv files with BOM as the first character in CSV files. This gets picked up as part of the header (and key name) by the parser. With the bom option set to true, it can handle csv files generated from excel or other programs.

const csvParser = csvParse({
  columns: true, 
  skip_empty_lines: true,
  bom: true