npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

stamp-stream

0.1.1

@mafintosh

npmRepoSnykSocket
Downloads:2
$ npm install stamp-stream
DailyWeeklyMonthlyYearly

Stream-Stamp

A through stream that stamps all incoming lines of data with a message and emits it back out

npm install stream-stamp

Usage

Usage is simple

var stamp = require('stream-stamp');
var stream = stamp('hello ');

stream.pipe(process.stdout); // "hello world\n" is printed

stream.write('wor');
stream.write('ld\n');

You can make dynamic stamps as well by passing in a function instead

var lines = 0;
var stream = stamp(function() {
	return (lines++)+' '; // prefix with line number
});

stream.pipe(process.stdout); // "0 first\n1 second\n2 third\n" is printed

stream.write('first\n');
stream.write('seco')
stream.write('nd\nthird\n');

Stream-Stamp can be useful to stamp output from an application with timestamp or similar. Assume we have a file called stamp.js

process.stdin
	.pipe(stamp(function() {
		return new Date().toGMTString()+' ';
	}))
	.pipe(process.stdout);
process.stdin.resume();

If we now call node my-app.js | node stream.js all log messages from my-app.js would be prefixed by a timestamp.

License

MIT