title: Streaming data from Firebase Realtime Database
body: <p>I have over 20k documents in my Realtime Database. I need to stream them, but I'm not even sure how to get started with it. This is kind of what I was trying to go for</p>
  
  <pre><code>sendEmail.get('/:types/:message', cors(), async (req, res, next) =&gt; {
      console.log(5);
      const types = JSON.parse(req.params.types);
      console.log('types', types);
      let recipients = [];
      let mails = [];
      if (types.includes('students')) {
          console.log(1);
          const tmpUsers = await admin.database().ref('Users').orderByChild('student').equalTo(true).once('value').then(r =&gt; r.val()).catch(e =&gt; console.log(e));
          recipients = recipients.concat(tmpUsers);
      }
      if (types.includes('solvers')) {
          console.log(2);
          let tmpUsers = await admin.database().ref('Users').orderByChild('userType').equalTo('person').once('value').then(r =&gt; r.val()).catch(e =&gt; console.log(e));
          tmpUsers = tmpUsers.concat(arrayFromObject(await admin.database().ref('Users').orderByChild('userType').equalTo('company').once('value').then(r =&gt; r.val()).catch(e =&gt; console.log(e))));
          recipients = recipients.concat(tmpUsers);
      }
  });
  </code></pre>
  
  <p>But this code causes my server to run out of memory. Someone suggested streams in my previous question, but as much as I like the idea, I have no idea how to actually do the streaming. I know it should be something like:</p>
  
  <pre><code>const fs = require('fs');
  const readStream = fs.createReadStream('path goes here');
  const data = [];
  readStream.on('data', chunk =&gt; {
      data.push(chunk);
  })
  readStream.on('end', () =&gt; {
      console.log(data);
      res.end(data);
  });
  </code></pre>
  
  <p>But how on earth do I pass a firebase query into the path?</p>
  
  <p>I tried this, but it said <code>Argument type Promise is not assignable to parameter type PathLike</code>, which makes sense, but how do I get around it?</p>
  
  <pre><code>const users = fs.createReadStream(admin.database().ref('News').once('value').then(r =&gt; r.val()))
  </code></pre>
  
  <p>To summarize: How do I stream data from a Firebase realtime database?</p>
  
  <p>Edit: 
  How is that a duplicate? These are 2 completely different questions. The starting code is the same but the ways of solving I'm asking about are completely different</p>