我正在尝试为我的程序添加一个简单的设置提示,在第一次启动应用程序之前,它会提示一些基本细节。我需要的其中一个输入是密码。当我读取这个密码时,我想确保(就像为sudo
输入密码时一样(它不会在用户键入时出现在用户的终端中。
如何在NodeJS中做到这一点?我正在寻找可以放入以下代码中的内容。
console.log('Failed to find config file');
// This echoes to the console - how can I do the same thing without the echo?
const password = prompt('Enter a password: ');
如果需要,我很乐意从NPM安装一个依赖项。
您可以使用prompt-sync
库提示输入密码。
import createPrompt from 'prompt-sync';
const prompt = createPrompt({});
// The prompt object's hide method gives a prompt where the input
// is hidden
const password = prompt.hide('Enter a password: ');