我是 Node.js 的新手。我知道它使用异步编程,但我需要编写一个循环来要求用户输入一些数据,然后在用户输入数据后,一次又一次地询问,直到循环结束。我尝试了这段代码,但输出如下:
插入数据?
插入数据?
插入数据?
当我想输入一些东西时,就像:aaallliii
for (index=1;index<=3;index++){
console.log("Insert Data?");
prompt.start();
prompt.get(['data'], function (err, result)
{
});
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能编写代码来像普通循环一样使用它?