blob: f142e30eda7baac34359783bdf654f6c42f0bc48 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# single-line-log
Node.js module that keeps writing to the same line in the console (or a stream). Very useful when you write progress bars, or a status message during longer operations. Supports multilines.
## Installation
npm install single-line-log
## Usage
``` js
var log = require('single-line-log').stdout;
// or pass any stream:
// var log = require('single-line-log')(process.stdout);
var read = 0;
var size = fs.statSync('super-large-file').size;
var rs = fs.createReadStream('super-large-file');
rs.on('data', function(data) {
read += data.length;
var percentage = Math.floor(100*read/size);
// Keep writing to the same two lines in the console
log('Writing to super large file\n[' + percentage + '%]', read, 'bytes read');
});
```
## .clear()
Clears the log (i.e., writes a newline).
``` js
var log = require('single-line-log').stdout;
log('Line 1');
log.clear();
log('Line 2');
```
## .stdout
Outputs to `process.stdout`.
## .stderr
Outputs to `process.stderr`.
## License
MIT
|