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

366
Vistas
How can i read a file with fs or without it, but i want to read row per row?

I want to read a file with fs, but so far i could not do that, never show the console 2222, why can not see the console?

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)
  }

or how can i read without fs, dont mind, but i need row per row

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

here you can go

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 Denunciar

0

you should listen the line event.here is a simple code.

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 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