title: How to pause downloading in Node.js by request module
body: <p>How can I pause while downloading a file and start again?</p>
  
  <p>Now I'm making download and show progress function with Node.js, javascript, html and electron. I thought it would be better if I can add pause function too.</p>
  
  <p>I searched the request module, but I couldn't find event about pausing download. this is my first time using node modules.</p>
  
  <p>Is there any event that I can add on my code? thanks!</p>
  
  <p>referred by <a href="https://ourcodeworld.com/articles/read/228/how-to-download-a-webfile-with-electron-save-it-and-show-download-progress" rel="nofollow noreferrer">this post</a>.</p>
  
  <pre><code>//download.js
  
  var request = require('request');
  var fs = require('fs');
  
  function downloadFile() {
      var a = event.currentTarget;
      var td = a.parentElement;
      var tr = td.parentElement;
  
      var id = '';
      var fileSize='';
      fileSize = '' + tr.querySelector('td').getAttribute('id');
      console.log(fileSize);
        var progressBar;
        var display;
      progressBar= tr.querySelector('progress');
      display= tr.querySelector('span');
      progressBar.value = 0;
      display.innerText = '0%';
    // Save variable to know progress
    var received_bytes = 0;
    var total_bytes = 0;
  
      var fileURL = "http://speedtest-ny.turnkeyinternet.net/"+fileSize;
    var finalPath = "./resources/"+fileSize;
    var req = request({
      method: 'GET',
      uri: fileURL
    });
  
    var out = fs.createWriteStream(finalPath);
    req.pipe(out);
  
    req.on('response', function(data) {
      // Change the total bytes value to get progress later.
      total_bytes = parseInt(data.headers['content-length']);
      progressBar.max = total_bytes;
    });
  
    req.on('data', function(chunk) {
      // Update the received bytes
      progressBar.max = total_bytes;
      received_bytes += chunk.length;
      progressBar.value = received_bytes;
      display.innerText = Math.floor((progressBar.value / progressBar.max) * 100) + '%'
    //  showProgress(received_bytes, total_bytes);
    });
  
    req.on('end', function() {
      //alert("File succesfully downloaded");
    });
  }
  </code></pre>
  
  <p><strong>HTML :</strong></p>
  
  <pre><code>&lt;!-- download.html --&gt;
  
  &lt;table width="500" cellpadding="0" cellspacing="0" border="1" class="blueone"&gt;
  
        &lt;tr&gt;&lt;th&gt;파일명&lt;/th&gt;&lt;th &gt;진행상황&lt;/th&gt;&lt;th&gt;&lt;a onclick="downloadClick()"&gt;다운로드&lt;/a&gt;&lt;/th&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td id="100Mb.dat" &gt;File10MB&lt;/td&gt;&lt;td&gt;&lt;progress id="progress" value="0"&gt;&lt;/progress&gt;&lt;span id="display"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;a class="checkBtn" onclick="downloadFile2(event)"&gt;다운로드&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td id="100mb.bin"&gt;File100MB&lt;/td&gt;&lt;td&gt;&lt;progress id="progress" value="0"&gt;&lt;/progress&gt;&lt;span id="display"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;a class="checkBtn" onclick="downloadFile(event)"&gt;다운로드&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td id="500mb.bin"&gt;File500MB&lt;/td&gt;&lt;td&gt;&lt;progress id="progress" value="0"&gt;&lt;/progress&gt;&lt;span id="display"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;a class="checkBtn" onclick="downloadFile4(event)"&gt;다운로드&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td id="1000mb.bin"&gt;File1GB&lt;/td&gt;&lt;td&gt;&lt;progress id="progress" value="0"&gt;&lt;/progress&gt;&lt;span id="display"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;a class="checkBtn" onclick="downloadFile(event)"&gt;다운로드&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td id="10Gb.dat"&gt;File10GB&lt;/td&gt;&lt;td&gt;&lt;progress id="progress" value="0"&gt;&lt;/progress&gt;&lt;span id="display"&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;a class="checkBtn" onclick="downloadFile3(event)"&gt;다운로드&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
  
    &lt;/table&gt;
  </code></pre>