title: How to send a video in chunks from a hapi js server
body: <p>I'm setting up a node js server built with hapi js framework. I created an endpoint which reads a video file from my server then sends back the chunk of data to the client. I'm using a react native on my client. I want to have a seamless video streaming from my nodejs server to my mobile app.</p>
  
  <p>I tried reading the file and sending it back to the client, but it takes time because It is downloading all the data first then sending it back to the client. </p>
  
  <pre><code>const { filename } = req.params;
  const readStream = fs.createReadStream(`uploads/videos/${filename}.mp4`);
    readStream.on('open',function(){
      //start to read de video 
    console.log("start..");
    });//open
  
    readStream.on('data',function(chunk){
    console.log("loading...", chunk)
    });//loading
  
    readStream.on("end",function(){
    console.log("ready");
    });//end 
  
    readStream.on('error', function (err){
    console.log(err);
    });
    return h.response(readStream)
      .type('video/mp4')
      .header('Content-type', 'video/mp4')
      .header("Accept-Ranges", "bytes")
      .header('Content-length', readStream.length);
  </code></pre>