I'm new in node.js. I know it uses asynchronous programming but I need to write a loop for asking user to input some data and then after user inputs data, ask again and again till the loop ends.
I tried this code but the output is like this:
Insert Data?
Insert Data?
Insert Data?
and when I wanna input something it's like: aaallliii
for (index=1;index<=3;index++){
console.log("Insert Data?");
prompt.start();
prompt.get(['data'], function (err, result)
{
});
}
how can I write the code to use it like normal loops?
I know it uses asynchronous programmingonly the asynchronous parts are asynchronous, the synchronous parts are ... drum roll ... syncrhonous ... what ispromptin your code?async/awaitfor the easiest solution, otherwise look into Promises and resolving them in series.promptis in some way asynchronous, then it's the wrong tool - a link to whatpromptis would help