Async function happening before another async function is done in Node.js

Now I realy don't know about async/await in node.js to be honest but I'm stuck :(

this is my code

async function main(){
    var pokemonID = getRandomPokemon();

    getJSON(pokemonID)
        .then(data => {getPokemonInfo(data)})
        const tempData = require('./temp_data.json');
        await down.load(tempData.pokemonImg)
        var tweetText = "Today's Pokemon of the day is " + tempData.pokemonName + ", which is a " + tempData.pokemonType + " type pokemon"
        await tweet.tweeter(tweetText)

}

main()

I don't get an error but the second async function executes before the first one.



Read more here: https://stackoverflow.com/questions/66334052/async-function-happening-before-another-async-function-is-done-in-node-js

Content Attribution

This content was originally published by B R U H at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: