我试图构建命令行程序,所以我使用了prompt npm library
我还使用了Promise来确保该方法
function () {
console.log("Hello something");}
当用户在控制台上输入内容后,执行,但是程序未等待用户输入。以下是我的代码段
//prompt code
var prompt = require('prompt');
var schema = {
properties: {
name: {
message: "enter your jira user name "
},
password: {
message: "Enter jira password",
hidden: true
}
}
};
//global declaration
var username;
var password;
// using promise to make sure that function executes after release() method
var letsPromise = new Promise(function(reslease, reject) {
prompt.start();
prompt.get(schema, function(err, result) {
//
// Log the results.
//
username = result.name;
password = result.password;
console.log(username);
console.log(password);
});
reslease();
});
//promise's then function
letsPromise.then(function() {
console.log("Hello something");
});