Tracks the download progress of a request made with mikeal/request
Tracks the download progress of a request made with request.
$ npm install request-progress
var fs = require'fs';var request = require'request';var progress = require'request-progress';// Note that the options argument is optionalprogressrequest''throttle: 2000 // Throttle the progress event to 2000ms, defaults to 1000msdelay: 1000 // Only start to emit after 1000ms delay, defaults to 0mson'progress'console.log'received size in bytes' statereceived;// The properties bellow can be null if response does not contain// the content-length headerconsole.log'total size in bytes' statetotal;console.log'percent' statepercent;on'error'// Do something with errpipefscreateWriteStream'doodle.png'on'error'// Do something with erron'close'// Saved to doogle.png!
Note that the
state object emitted in the
progress event is reused to avoid creating a new object for each event.
Released under the MIT License.