我正在 JavaScript 中编写一些代码,并使用命令 node filename.js
使用命令行运行它。我希望用户在命令行上输入输入值,并使用这些值进行进一步处理和输出。
最佳答案
使用prompts npm 包
npm install --save 提示
const prompts = require('prompts');
const questions = [
{
type: 'text',
name: 'dish',
message: 'Do you like pizza?'
},
{
type: prev => prev == 'pizza' ? 'text' : null,
name: 'topping',
message: 'Name a topping'
}
];
(async () => {
const response = await prompts(questions);
})();
关于javascript - 如何在javascript中接受用户在命令行上的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58060534/