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

237
Views
Uso de fs.createReadStream y fs.createWriteStream para varios archivos

Estoy tratando de recorrer varios archivos con fs.createReadStream y no sé cómo leer el segundo archivo.

 const fs = require('fs') const csv = require('csv-parse') const parser = csv({ ... }) const files = process.argv.slice(2) async function analyzeFiles () { for (const file of files) { const string = file console.log(`Analyzing ${file}.`) await runFile(file, string) console.log(`Analyzed ${file}.`) } } async function runFile (filepath, string) { return new Promise(function (resolve, reject) { const shimmedData = {} let fileName = '' fs.createReadStream(filepath) .pipe(parser) .on('data', (row) => { // ... fileName = 'something dynamic from row' shimmedData[index] = row // Or something similar, not sure this matters }) .on('error', (e) => { console.log('BONK', e) }) .on('end', () => { fs.writeFile(`${fileName}.json`, JSON.stringify(shimmedData), (err) => { if (err) { console.log(err) reject(err) } else { console.log('File written successfully.') resolve() } }) }) }) } analyzeFiles()

Y luego ejecuto node script.js file1.txt file2.txt file3.txt

Cuando ejecuto esto, solo se guardará el primer archivo. Al examinarlo con los registros de la consola, parece que para el segundo archivo nunca se llama a fs.createReadStream .

¿Qué me estoy perdiendo?

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