Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

328
Visualizações
Using inquirer js inside a loop is not waiting for user input

I have an array of changes to apply to the database and for every change I need user confirmation. Therefore I'm using inquirer js to ask the user if he wants to apply those changes.

I tried outside the loop and works but if I do it inside the loop it don't. It shows the question but the loop keeps going not letting the user to answer yes or no. I'm looking over SO and the internet and I can't fid any example or code like this, is what amb trying even possible?

This is my code:

changes.map(change => {
                      inquirer.prompt([{
                        name: "operate",
                        type: "confirm",
                        message: `Updatade database with ${change.description}?`,
                    }, ])
                    .then((operate) => {
                        if (operate.replace) {
                            green(
                                `Database has been updated`
                            );
                        } else {
                            red(
                                `Database hs not been updated`
                            );
                        }
                    });}

Also tried with async/await but I'm having the same issue.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I found the issue. On the loop I was creating all the prompts with the same name therefore didn't result. After changing that now it works perfect.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda