我只是想等待用户输入密码,然后在继续使用其余代码之前使用它.错误是Cannot read property 'then' of undefined.
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Password: ', password => {
rl.close();
return decrypt(password);
}).then(data =>{
console.log(data);
});
function decrypt( password ) {
return new Promise((resolve) => {
//do stuff
resolve(data);
});
}
Run Code Online (Sandbox Code Playgroud) 我正在为一个开源框架创建一个示例项目。要运行我的演示,它的一些依赖项必须在其他端口上运行本地服务器。
我宁愿只为他们提供一个命令来运行,而不是告诉他们打开多个终端并在每个终端中运行多个命令。
解决此问题的最佳/最合适/最优雅的方法是什么?