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

262
Vistas
Console is overwriting one console.log with another?

I have an application that queries a mysql database. It starts out:

function init() {
    console.log(`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    What would you like to do?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    `);
    return inquirer
        .prompt({
            type: "list",
            name: "options",
            message: "Select one",
            choices: list,
        })
        .then((data) => {
            return redirectQuestion(data.options);
        })
        .then(() => init())
        .catch(err => {
            console.log(err);
        })
}

init()

The redirectQuestion function takes the user to a function with switch cases to find the correct query, for example:

class View {
    constructor(table = '') {
        this.table = table
        this.statement = `SELECT * FROM ${this.table} ORDER BY id`
    }
    getTable() {
        db.query(
            this.statement, (err, results, fields) => {
                if (err) {
                    console.log("There was an error with your request")
                }
                console.table(results)
            }
        )
    }
}

The problem is, that after this runs, there is a recursive call to init() to bring up the options again. The options, instead of appearing below the data from the database, appear above them, and if I move to select other options, it will then create another table which overwrites the bottom part of the data.

Now, it's probably a less than desirable way to write the function out, but I need to have a way to recall the table, and still display the data, and I am not sure what is going wrong.

enter image description here

enter image description here

enter image description here

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