title: What is the best way to download a big file in NodeJS?
body: <p>The below server code is working fine for 5GB file using
   <code>wget http://localhost:11146/base/bigFile.zip</code> but not using client side code. </p>
  
  <blockquote>
    <p>Server side code.</p>
  </blockquote>
  
  <pre><code>var http = require("http");
  var fs = require("fs");
  var filename = "base/bigFile.zip";
  
  var serv = http.createServer(function (req, res) {
      var stat = fs.statSync(filename);
      res.writeHeader(200, {"Content-Length": stat.size});
      var fReadStream = fs.createReadStream(filename);
      fReadStream.on('data', function (chunk) {
         if(!res.write(chunk)){
             fReadStream.pause();
         }
     });
     fReadStream.on('end', function () {
        res.end();
     });
     res.on("drain", function () {
        fReadStream.resume();
     });
  });
  
  serv.listen(1114);
  </code></pre>
  
  <blockquote>
    <p>Client side code using Request module. What is wrong in this code? </p>
  </blockquote>
  
  <pre><code>var request = require('request')
  request('http:/localhost:11146/base/bigFile.zip', function (error, response, body) {
    console.log('error:', error); // Print the error if one occurred
    console.log('statusCode:', response &amp;&amp; response.statusCode); // Print the response status code if a response was received
    console.log('body:', body); // Print the HTML for the Google homepage.
  });
  </code></pre>
  
  <blockquote>
    <p>error for above client side code is below - </p>
  </blockquote>
  
  <pre><code>error: Error: Invalid protocol
      at Request.init (/Users/air/Projects/node_modules/request/request.js:338:51)
      at new Request (/Users/air/Projects//node_modules/request/request.js:105:8)
      at request (/Users/air/Projects/Vertico/Vertico-CLI/node_modules/request/index.js:53:11)
      at Object.&lt;anonymous&gt; (/Users/air/Projects/req.js:2:1)
      at Module._compile (module.js:569:30)
      at Object.Module._extensions..js (module.js:580:10)
      at Module.load (module.js:503:32)
      at tryModuleLoad (module.js:466:12)
      at Function.Module._load (module.js:458:3)
      at Function.Module.runMain (module.js:605:10)
  statusCode: undefined
  body: undefined
  </code></pre>
  
  <blockquote>
    <p>I revised client side to use <code>wget</code> shell process instead of request package, that code is below, the problem is - I am not able to see nice download progress of wget, any work around for this code, such that I can see the progress bar in child process. </p>
  </blockquote>
  
  <pre><code>const fs = require('fs');
     const child_process = require('child_process');
  
     var workerProcess = child_process.spawn('wget', ['-O','fdsf.zip', 'http://localhost:11146/base/bigFile.zip']);
  
     workerProcess.stdout.on('data', function (data) {
       console.log('stdout: ' + data);
     });
  
     workerProcess.stderr.on('data', function (data) {
       //console.log('stderr: ' + data);
     });
  
     workerProcess.on('close', function (code) {
        console.log('Download Completed' + code);
     });
  </code></pre>
  
  <p>So finally I want to know how to download a file using client side code written in nodejs?</p>