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:
- Ask question and wait untill I enter the answer.
- Process the question (with the codes in
run()
) - Once it's done, go back to question 1.
How can I do this?
CodePudding user response:
Instead of doing
for( ; ; ) {
run();
}
Do this inside run
function
while (true) {
const answers = await form();
//other codes
//~~
}