title: Wait all promises in a map function
body: <p>I want to wait to read all my pictures in a map function</p>
  
  <p>I tried this</p>
  
  <pre><code>let buffer = [];
  // Folder of the dataset.
  const rootFolder = './dataset'
  console.log("Entering in folder dataset");
  fs.readdirSync(rootFolder);
  // For each folders
  const files = fs.readdirSync(rootFolder).map(dirName =&gt; {
    if(fs.lstatSync(path.join(rootFolder, dirName)).isDirectory()){
      console.log(`Entering in folder ${path.join(rootFolder, dirName)}`);
      // For each files
      fs.readdirSync(path.join(rootFolder, dirName)).map(picture =&gt; {
        if(fs.lstatSync(path.join(rootFolder, dirName, picture)).isFile()){
          if(picture.startsWith("norm")){
            return fileToTensor(path.join(rootFolder, dirName, picture)).then((img) =&gt; {
              buffer.push(img);
            }).catch((error) =&gt; {console.log(error)});
          }
        }
      });
    }
  });
  
  Promise.all(files);
  console.log(buffer);
  
  async function fileToTensor(path) {
    return await sharp(path)
    .removeAlpha()
    .raw()
    .toBuffer({ resolveWithObject: true });
  }
  
  </code></pre>
  
  <p>But my buffer is still empty...</p>
  
  <p>I know promises exist but I don't know how can I include them in map(map())</p>
  
  <p>Thanks you :)</p>