Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

294
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda