Output one line and move to beginning of line. Useful for progress bars and counters with no breaks in the terminal
JavaScript
Latest commit 515b3b9 Sep 9, 2016 @freeall 1.1.2
Permalink
Failed to load latest commit information.
.gitignore Added .gitignore Feb 27, 2016
LICENSE Add license text Aug 26, 2015
README.md Updated example in readme May 10, 2014
index.js Fix previousLineCount calculation (#10) Sep 9, 2016
package.json 1.1.2 Sep 9, 2016
test.js Moved test case to test.js Feb 27, 2016

README.md

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

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).

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