I used async and await to achieve this but somehow the 2nd function gets called without even waiting for the 1st function to complete.
Is async and await best way to do this?
In this case do I need to call 1st function inside of second function or can it be called inside init function one after the other?
const prompt = require('prompt');
const properties = [
{
name: 'module_name',
default: 'custom-module',
description: "Name your Application module",
type: 'string'
},
{
name: 'application_home',
description: "Provide Application Home location (absolute path)",
message: "Your Application Home location should be a clone of Application Github repo and should have package.json",
type: 'string',
required: true
}
];
let module_name;
let application_home;
/**Prompt user to get mandatory details */
const getModuleDetails = async () => {
prompt.start();
prompt.get(properties, function (err, result) {
if (err) { return onErr(err); }
module_name = result.module_name;
application_home = result.application_home;
return;
});
}
/**Verbose */
const verboseDetails = async () => {
await getModuleDetails()
console.log('Command-line input received:');
console.log('Module Name: ' + module_name);
console.log('Application Home location: ' + application_home);
}
const init = async () => {
//getModuleDetails();
await verboseDetails();
}
init();
Update
/**Prompt user to get mandatory details */
const getModuleDetails = async () => {
prompt.start();
const result = await prompt.get(properties);
module_name = result.module_name;
application_home = result.application_home;
}
const verboseDetails = async () => {
console.log('Command-line input received:');
console.log('Module Name: ' + module_name);
console.log('Botpress Home location: ' + application_home);
}
const init = async () => {
await getModuleDetails();
await verboseDetails();
}
init();