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

195
Views
Nodejs wait user to give input?

I am looking for looping program continuously, but the problem looks like the program run without waiting for user make an input

const inquirer = require('inquirer');

const questions = [{
  type: 'input',
  name: 'name',
  message: "What's your name"
}];

do {
  inquirer.prompt(questions).then(answers => {
    console.log(`Hi, ${answers['name']}`);
  });
} while (true);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simple way to wait for user input is to use async/await. First you need to wrap block into self executing async function and then use await to get user response.

const inquirer = require('inquirer');

const questions = [{
  type: 'input',
  name: 'name',
  message: "What's your name"
}];

(async () => {
    do {
        const answers = await inquirer.prompt(questions);
        console.log(`Hi, ${answers['name']}`);
    } while (true);
})();
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!