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

124
Views
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 answers
Answer question

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 Report
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!