[英]How is it possible in Node js to display list of options via console log and ask user to input a option from the displayed list via console log
How is it possible in Node js to display list of options via console log and ask user to input a option from the displayed list via console log如何在 Node js 中通过控制台日志显示选项列表并要求用户通过控制台日志从显示的列表中输入一个选项
Expected behavior user@desktop:~$ node test.js预期行为 user@desktop:~$ node test.js
- Option 1选项1
- Option 2选项 2
- Option 3选项 3
Select option to continue: 3 You have selected option 3 Select 选项继续:3 您已选择选项 3
Figured out a method using inquirer module想出一个使用查询器模块的方法
const inquirer = require('inquirer');
function main() {
inquirer
.prompt([
{
type: 'list',
name: 'Options',
message: 'Select an Item from below list',
choices: ['alligator', 'crocodile', 'Exit'],
},
])
.then(answers => {
if (answers.Options == "Exit"){
process.exit()
} else {
console.info('Answer:', answers.Options);
}
});
}
if (require.main === module) {
main();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.