title: Wait for Firebase data to load before rendering NodeJS page after forEach with Promise.all()
body: <p>I'm trying to create a page that loads multiple data sets from Firebase, and then passes them to the NodeJS rendered page. I'd appreciate some help in ensuring that this happens after the forEach iterations; namely, I'm not sure how to get the Firebase forEach iterations to be part of my promises.</p>
  
  <p>Thank you so much!</p>
  
  <pre><code>router.get('/', function(req, res, next) {
  
      var getBrands = brandRef.once('value').then(function(snapshot){
          var brands = [];
  
          snapshot.forEach(function(childSnapshot){
              console.log(childSnapshot.val()['name']);
              brands.push({'name' : childSnapshot.val()['name'] });
          });
  
          return brands;
      });
      var getStores = storeRef.once('value').then(function(snapshot){
          var stores = [];
  
          snapshot.forEach(function(childSnapshot){
              stores.push({'name' : childSnapshot.val()['name'] });
          });
  
          return stores;
      });
      var getProducts = productRef.once('value').then(function(snapshot){
          var products = [];
  
          snapshot.forEach(function(childSnapshot){
              products.push({'name' : childSnapshot.val()['name'] });
          });
  
          return products;
      });
  
      console.log(brands, stores, products);
      Promise.all([getBrands, getStores, getProducts]).then(function(results){
  
          res.render('index', { title: 'MStore Demo Portal', stores: results[0], brands: results[1], products: results[2] });
      });
  });
  </code></pre>