Credentials prompt for CLI apps
$ npm install inquirer-credentials --save
const inquirerCredentials = require('inquirer-credentials');
const username = {
name: 'username',
type: 'input',
hint: 'please, tell your username',
env: 'USERNAME' // uses process.env['USERNAME'] if exists and don't ask user
};
const password = {
name: 'password',
type: 'password',
env: 'PASSWORD' // uses process.env['PASSWORD'] if exists and don't ask user
};
const creds = inquirerCredentials('.test');
creds
.run([username, password])
.then(function(result) {
result.data //=> { username: 'string', password: 'string' }
result.save() // persists config to fs, result is an instance of https://github.com/ewnd9/dot-file-config
Object.keys(creds.config.data) //=> ['username', 'password']
})
.catch(function(err) {
console.log(err.stack || err);
});
MIT © ewnd9