Node js how to return variable in async await promise

Solution 1:

You can use async/await and Promise.all() like this:

export async function ss3ListAllFilesTags(bucket: string, folder: string, tag: string){
  let params = {
    Bucket: `${TypesOptions[bucket].bucket}`,
    Prefix: `${folder}`,
    // MaxKeys: 1000,
  };
  try {
    const data = await s3.listObjectsV2(params).promise()
    var tab: string[] = [], t: any;

    await Promise.all(
      Object.entries(data.Contents).map((element) =>
        serviceDownloadFileWithTags(bucket, element[1].Key).then((dat) => {
          dat = JSON.parse(dat)
          if (dat['TagSet'][0].Value == tag || dat['TagSet'][1].Value == tag) {
            tab.push(element[1].Key)
            console.log(tab)
          }
        })
      )
    )

    console.table(tab);
    return tab;
  } catch (err) {
    return err
  }
}