title: How to send stream of json object to the client?
body: <p><em>This can be a duplicate question but cant find any solution out there. I already tried to search it on this fast hours but I am out of luck.</em></p>
  
  <p>My question is how I can send <em>stream</em>(idk if stream is the right term) of json objects to the client.</p>
  
  <p>Example I am reading data on the DB, and on every 5 records it found I will send the data to the client in json format. Then read the data on the client using Angular httpclient lib.</p>
  
  <p>I already tried expressjs <code>response.write()</code>, but the client was unable to receive the data until I call <code>response.end()</code>.</p>
  
  <p>What is the proper way of doing this?</p>
  
  <p>I was thinking about socket.io but that would be overkill.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Other exmple</p>
  
  <pre><code>function getData(res: Response, req: Request):void {
    for(let i = 0; i&lt;100; i++{
      res.write(JSON.stringify({data:1}) + '\n');
    }
  
    res.end(); // There is data received on the browser until this was called.
  }
  </code></pre>
  
  <p>Or something like this. I was expecting a data will reach every 1 second but they came up at the same time after 10s.</p>
  
  <pre><code>function getData(res, req){
    const s = setInterval(()=&gt;{
      res.write(JSON.stringify({value: 'test value'}));
    }, 1000);
  
    setTimeout(()=&gt;{
      clearInterval(s);
      res.end();
    }, 10000);
  }
  </code></pre>