title: Promise All in Node.js with a forEach loop
body: <p>I have a function that reads a directory and copies and creates a new file within that directory.</p>
  
  <pre class="lang-js prettyprint-override"><code>function createFiles (countryCode) {
    fs.readdir('./app/data', (err, directories) =&gt; {
      if (err) {
        console.log(err)
      } else {
        directories.forEach((directory) =&gt; {
          fs.readdir(`./app/data/${directory}`, (err, files) =&gt; {
            if (err) console.log(err)
            console.log(`Creating ${countryCode}.yml for ${directory}`)
            fs.createReadStream(`./app/data/${directory}/en.yml`).pipe(fs.createWriteStream(`./app/data/${directory}/${countryCode}.yml`))
          })
        })
      }
    })
  }
  </code></pre>
  
  <p>How do I do this using promises or Promise All to resolve when it's complete?</p>