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

359
Views
¿Cómo puedo leer un archivo con fs o sin él, pero quiero leer fila por fila?

Quiero leer un archivo con fs, pero hasta ahora no pude hacer eso, nunca mostrar la consola 2222, ¿por qué no puedo ver la consola?

 const inputFileName = "./input.txt"; fs.createWriteStream(outputFileName, { flags: "a" }); const fileStream = fs.createReadStream(inputFileName); const file = readline.createInterface({ input: fileStream, crlfDelay: Infinity, }); for await (const row of file) { console.log(2222) }

o cómo puedo leer sin fs, no importa, pero necesito fila por fila

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

0

aquí puedes ir

 function readTextFile(file) { var rawFile = new XMLHttpRequest(); rawFile.open("GET", file, false); // open with method GET the file with the rawFile.onreadystatechange = function () { if(rawFile.readyState === 4) // readyState = 4: request finished and response is ready { if(rawFile.status === 200) // status 200: "OK" { var allText = rawFile.responseText; // Returns the response data var str_array = allText.split('\n'); //convert to array // use map function str_array.map((value, key)=> { console.log(value); //row per row data }) } } } rawFile.send(null); //Sends the request to the server Used for GET requests with param null } readTextFile("demo.txt"); //pass the file path
about 4 years ago · Juan Pablo Isaza Report

0

deberías escuchar el evento line . Aquí hay un código simple.

 let fs = require('fs'); let readline = require('readline'); let strInputFileName = 'input.txt'; let fRead = fs.createReadStream(strInputFileName); fRead.on('end', ()=>{ console.log('end'); }); let objReadline = readline.createInterface({ input: fRead, }); objReadline.on('line', (strLine)=>{ console.log(strLine) });
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!