My function doesnt wait to my variable to be storaged [duplicate]

Im using this function but the console prints before i get the value, does anyone … Read more My function doesnt wait to my variable to be storaged [duplicate]

Im using this function but the console prints before i get the value, does anyone know how to fix it? Thanks!

async function getContent(){
  // Load client secrets from a local file.
  let my_content;
  await fs.readFile('credentials.json', async (err, content) => {
    if (err) return console.log('Error loading client secret file:', err);
    my_content = await JSON.parse(content);
  });
  console.log(my_content);
}

Source: JavaSript – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *