I am using npm inquirer
for the first time.
I am using a code similar to this:
const inquirer = require("inquirer");
const questions = [
{
type: "checkbox",
name: "collections.telemetria",
message: "Select collections of database telemetria",
choices: [
"chimera-11/14/2019,-4:22:38-PM",
"chimera-11/14/2019,-4:28:26-PM"
]
},
{
type: "checkbox",
name: "collections.testa",
message: "Select collections of database testa",
choices: ["testa_c"]
}
];
async function main() {
const collections = (await inquirer.prompt(questions)).collections;
console.log("collections:", collections);
const outPath = await inquirer.prompt([
{
type: "input",
name: "outPath",
default: "./",
message: "Insert the output path"
}
]).outPath;
console.log(outPath);
}
main();
The problem is that when it comes to the question of type input to be answered, the word undefined appears and I cannot put any input.
Here is a code sandbox: https://codesandbox.io/s/stoic-kowalevski-dgg5u
Thanks to the advice of Shivam Sood, I found that there was only a mistake in the code. I forgot to put the await inquirer.prompt([...])
inside the parenthesis before calling the property outPath
of the expected result.
So the right code should be:
const outPath = (await inquirer.prompt([
{
type: "input",
name: "outPath",
default: "./",
message: "Insert the output path"
}
])).outPath;
console.log(outPath);