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

162
Vistas
Readline infinitely while handling async console logs in Node.js

I'm trying to create a script where you can write commands:

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

let askCommands = async () => {
  readline.question('> ', async (command) => {
    // If user exits close readline
    if(command === 'exit') {
      readline.close();
      return process.exit();
    }
    switchCommands(command);
    askCommands();
  })
}

let switchCommands = (command) => {
  if(command === 'test') {
    setTimeout(() => {
      console.log('Hello!')
    }, 1000)
  } else {
    console.log(`Invalid command '${command}'`)
  }
}

askCommands();

It works fine until I use an async console.log(). This is because the script writes the async outputs without removing the '> ' and then generates a new line that does not have the '> '. Moreover, if in this new line you write any character and then delete it the '> ' is added automatically.

I would like to write async logs without having the '> ' before them and without removing the '> ' where users write the commands. Is there any easy solution to this problem?

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