title: Node JS Request + Express Pipe
body: <p>I have a problem with streaming video files from a server to another.</p>
  
  <p>I wrote this script</p>
  
  <pre class="lang-js prettyprint-override"><code>var request = require("request"),
      express = require("express");
  
  var app = express();
  
  app.get("/cast", function(req, res) {
  
      var url = req.query.video;
  
      res.writeHead(200, {
          'Content-Type': 'video/mp4'
      });
  
      request({
          url: url,
          headers: {
              Referer: "http://example.com/1706398/" + url
          }
      })
          .on('response', function(response) {
  
              response.on('data', function(data) {
                  console.log("data chunk received: " + data.length)
              });
  
              response.on('end', function(data) {
                  console.log('Video completed');
              });
  
          })
          .pipe(res);
  
  });
  
  app.listen(8080);
  </code></pre>
  
  <p>But video response sometimes works sometimes is corrupted, instead if request's data is written in a writeable buffer and saved as video file  it works with any url.
  I cannot found any error or problem in my code, here some urls :</p>
  
  <blockquote>
    <p>Here some url that I tryed:
    <a href="https://gist.github.com/FrancisCan/f2bb86f8ff73b45fa192" rel="nofollow">https://gist.github.com/FrancisCan/f2bb86f8ff73b45fa192</a></p>
  </blockquote>
  
  <p>Thanks :)</p>