Tracks the download progress of a request made with mikeal/request, giving insight of various metrics including progress percent, download speed and time remaining
Tracks the download progress of a request made with request, giving insight of various metrics including progress percentage, download speed and time remaining.
Installation
$ npm install request-progress
Usage
var fs = require('fs');var request = require('request');var progress = require('request-progress');// The options argument is optional so you can omit itprogress(request('https://az412801.vo.msecnd.net/vhd/VMBuild_20141027/VirtualBox/IE11/Windows/IE11.Win8.1.For.Windows.VirtualBox.zip'), { // throttle: 2000, // Throttle the progress event to 2000ms, defaults to 1000ms // delay: 1000, // Only start to emit after 1000ms delay, defaults to 0ms // lengthHeader: 'x-transfer-length' // Length header to use, defaults to content-length}).on('progress', function (state) { // The state is an object that looks like this: // { // percent: 0.5, // Overall percent (between 0 to 1) // speed: 554732, // The download speed in bytes/sec
If the request's response does not include the content-length header, the values of some metrics will be null.
Also speed and time.remaining will be null until it can be calculated.
The state object emitted in the progress event is reused to avoid creating a new object for each event.
If you wish to peek the state object at any time, it is available in request.progressState.