Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Use csv-parser to only return file headers

I'm looking at the NPM package csv-parser that parses csv files to JSON. Based on the example provided, you can read a csv file row by row in the following manner:

fs.createReadStream('data.csv')
  .pipe(csv())
  .on('data', (rowData) => console.log(rowData))
  .on('end', () => { console.log("done reading the file") });

Is there any way I can only return the header values of the CSV file instead?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use headers event

fs.createReadStream('data.csv')
  .pipe(csv())
  .on('headers', (headers) => {
    console.log(`First header: ${headers[0]}`)
  })

From official docs

enter image description here

over 4 years ago · Santiago Trujillo Report

0

https://github.com/mafintosh/csv-parser#headers-1

Emitted after the header row is parsed. The first parameter of the event callback is an Array[String] containing the header names.

use .on('headers', (headers) event

fs.createReadStream('data.csv')
  .pipe(csv())
  .on('headers', (headers) => {
    console.log(headers)
  })
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!