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

126
Visualizações
Prevent node.js application from exiting once the process is done

I wrote a really basic nodejs application which look like this:

#!/usr/bin/env node

const inquirer = require("inquirer");
const chalk = require("chalk");
const figlet = require("figlet");
const shell = require("shelljs");
const fs = require('fs');

//Defining some functions
//~~

//The main part of the code
const run = async function() {
    const answers = await form();
    //other codes
    //~~
}

run();

The main purpose of the code is to use the inquirer module to ask some question in the console, and then process the answers in the run() part. It does perfect job on that. It successfully asks the question and do what it should do with the answers.

However, The process would exit once the answer have been processed. What I want is once the answer have been processed, I want it to answer the same question again, and keep repeating that until I terminate the process manually.

I tried this:

for( ; ; ) {
    run();
}

However, It would then answer questions again and again without waiting for answers. Here is how the console looked like: console output

I want it to do these:

  1. Ask question and wait untill I enter the answer.
  2. Process the question (with the codes in run())
  3. Once it's done, go back to question 1.

How can I do this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Instead of doing

for( ; ; ) {
    run();
}

Do this inside run function

while (true) {
    const answers = await form();
    //other codes
    //~~
}
about 4 years ago · Juan Pablo Isaza 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