I've got a function which uses inquirer to ask a series of questions and then calls a function in the inquirer.prompt(q).then()
function with the answers. This works perfectly well but I'm trying to do some refactoring of my app and I want to be able to make my function return the set of answers to be called elsewhere. However, the code I have seems to return nothing at all. I thought I'd followed the examples correctly but apparently not. Can someone shed some light on the issue, please?
Here is the function:
const inquirer = require('inquirer')
const questions = require('../data/questions')
// Ask the user the predefined questions
module.exports = questionTime = async () => await inquirer.prompt(questions)
I've also tried to write it out the long-form way to see if that helped but to no avail:
module.exports = questionTime = async function () {
const answers = await inquirer.prompt(questions)
return answers
}
If I console.log
answers
instead of returning then I can see the output but if I import the function to another file and console.log
that I get nothing:
e.g. console.log(questionTime())