Inquirer.js
Inquirer.js copied to clipboard
How to set default value for an answer?
I need to set the default answer even if when() succeeds from the beginning which in turn not will display the question for the user.
{
type: 'input',
name: 'MYSQL_INCLUDE_DIR',
message: 'Enter path to mysql headers',
default: MYSQL_INCLUDE_DIR,
when: (answers) => {
return !fs.existsSync(MYSQL_INCLUDE_DIR)
},
validate: (path) => {
return fs.existsSync(path)
}
}
inquirer.prompt(questions)
.then((answers) => {
// answers.MYSQL_INCLUDE_DIR will be undefined if the default directory exists.
})
This issue is related to the following SO question:
https://stackoverflow.com/q/52842442/1047662