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

154
Vistas
JavaScript version of while True loop

I wrote this bit of code

while True:
   text = input('type here > ')
   print text

I've tried the below but it doesnt seem to be working

I'm having bit of a struggle trying to create a JavaScript version of it, since it seems js while loops constantly rerun but python seems to wait for input before rerunning. I am using the readline module to receive input from the console.

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

while (true) {
 rl.question('type here > ', text => {
       console.log(text)
    })
}

Is there something im getting wrong? Im fairly new to programming

Any solutions?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

If what you are trying to do is get input from the console in JavaScript you can use NodeJS process.stdin the implementation below :

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let input = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    input += inputStdin;
});

process.stdin.on('end', _ => {
    input = input.trim()
        .split('\n')
        .map(str => str.trim());

    // calling the function that works on the input
    doSomething();
});


function readInput() {
    return input[currentLine++];

}

Sample function to do something with what you get from the console

function doSomething() {
    console.log(readInput())
}
about 4 years ago · Santiago Gelvez 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