title: return from forEach in node.js to loop through firebase results
body: <p>How can I get a return after I loop through all my firebase results to properly finish my cloud function?</p>
  
  <pre><code>var count = 0;
  return ref.child('/records').once('value').then(snap=&gt;{
      snap.forEach(snapChild=&gt;{
          var ucName = ${snapChild.val().name.toUpperCase();
          var update = {'name':ucName);
          ref.child(`/records/${snapChild.key}`).update(update).then(()=&gt;{
              count++;
              res.write(`&lt;p&gt;${ucName} updated&lt;/p&gt;`);
          });
      })
  }).then(()=&gt;{
      return res.end(`&lt;p&gt;end of list (${count} records)&lt;/p&gt;`);
  })
  </code></pre>
  
  <p>It actually does what it is supposed to do but the counter stays at 0 and I get an error 'write after end' - I guess due to the missing return from forEach.</p>