title: How to wait for Promise.all to resolve before returning values in async function (express JS)
body: <p>I'm pretty new to JS and especially async programming. I am trying to build an Express+React app that displays a gitHub user's info (including a few repos with 5 commits).</p>
  <p>To do the latter, I am using Promise.all and map to get the commits for each repo in an array, and returning an array with the commits added to each repo.</p>
  <p>When I console.log the new repo in the map function, it works, but when I try to return the array, the objects are undefined.</p>
  <p>I assume this is because the return is executing before the Promises have resolved. Can anyone help me out with this?</p>
  <pre><code>//takes a username and collection of repos and finds their commits using fetch to github API. Returns the array of repos with their commits as a new property
  const getGitHubCommits = async (username, repos) =&gt; {
    try {
      const repositories = await Promise.all(
        repos.map(async (repo) =&gt; {
          fetch(`https://api.github.com/repos/${username}/${repo.name}/commits?per_page=5`).then(response =&gt; response.json())
            .then(async response =&gt; {
              repo.commits = response.slice(0, 5)
              console.log(repo)
              return await repo
            })
        })
      );
  
      console.log(repositories)
      return repositories
    } catch (error) {
      console.log(error)
      return &quot;No commits found found&quot;
    }
  }
  </code></pre>