1 Flexible ascii progress bar.
11 First we create a `ProgressBar`, giving it a format string
12 as well as the `total`, telling the progress bar when it will
13 be considered complete. After that all we need to do is `tick()` appropriately.
16 var ProgressBar = require('progress');
18 var bar = new ProgressBar(':bar', { total: 10 });
19 var timer = setInterval(function () {
22 console.log('\ncomplete\n');
30 These are keys in the options object you can pass to the progress bar along with
31 `total` as seen in the example above.
33 - `total` total number of ticks to complete
34 - `width` the displayed width of the progress bar defaulting to total
35 - `stream` the output stream defaulting to stderr
36 - `complete` completion character defaulting to "="
37 - `incomplete` incomplete character defaulting to "-"
38 - `clear` option to clear the bar on completion defaulting to false
39 - `callback` optional function to call when the progress bar completes
43 These are tokens you can use in the format of your progress bar.
45 - `:bar` the progress bar itself
46 - `:current` current tick number
47 - `:total` total ticks
48 - `:elapsed` time elapsed in seconds
49 - `:percent` completion percentage
50 - `:eta` estimated completion time in seconds
56 In our download example each tick has a variable influence, so we pass the chunk
57 length which adjusts the progress bar appropriately relative to the total
61 var ProgressBar = require('../');
62 var https = require('https');
64 var req = https.request({
65 host: 'download.github.com',
67 path: '/visionmedia-node-jscoverage-0d4608a.zip'
70 req.on('response', function(res){
71 var len = parseInt(res.headers['content-length'], 10);
74 var bar = new ProgressBar(' downloading [:bar] :percent :etas', {
81 res.on('data', function (chunk) {
82 bar.tick(chunk.length);
85 res.on('end', function () {
93 The above example result in a progress bar like the one below.
96 downloading [===== ] 29% 3.7s
99 You can see more examples in the `examples` folder.