So I have this asynchronous function with inquirer and fs.writeFile inside
(async () => {
...
if (process.env.IG_USERNAME && process.env.IG_PASSWORD) {
console.log(`Used as ${chalk.green(process.env.IG_USERNAME)}`);
} else {
console.log(`\nInstagram account data is not yet put in \nInputting in...`);
await inquirer.prompt(questions).then((answers) => {
let file = `IG_USERNAME=${answers.username}\nIG_PASSWORD=${answers.password}\n#ONLINE_MODE=true`;
fs.writeFile(".env", file, (err) => {
if (err) console.log("Something went wrong..");
else console.log(`Used as ${chalk.green(process.env.IG_USERNAME)}`);
});
});
}
await login();
...
})();
the login();
function needs the .env variable, i input it using inquirer but the login();
function get executed before the inquirer answer get processed.
What should I do to make the login();
waits until the fs.writeFile
is finished?