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

263
Views
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
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!