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

286
Views
NodeJs csv-parse await inside on('data')

I have a code, which reades .csv line by line and saves each parsed row to the database

const csv = require('csv-parse')
const errors = []
csv.parse(content, {})
    .on('data', async function (row: any) {
         const error = await tryToSaveToDatabase(row);
         if (error) {
            errors.push(error)
         }
     })
    .on('end', function () {
      // somehow process all errors
    })

but, unfortunately, .on('end', ... block is beeing called earlier then all await block succeded.

I have read NodeJs Csv parser async operations - seems we cannot use await inside .on('data', ... callback.

What is the correct way to perform such thing - if I want to read .csv line by line (files might be very huge - so it must be performed in a streaming manner) and collect some errors while saving to database? (these errors are displayed on frontend then)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

https://csv.js.org/parse/api/async_iterator/ This solution reads .csv line by line

about 4 years ago · Juan Pablo Isaza 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!