node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Add a color and a prefix to each line in a stream

## Install

To install color-prefix-stream, simply use npm:

npm install color-prefix stream --save

## Example

The example below can be found here and ran using node example.js. It uses color-prefix-stream to print multiple lines using random-picked colors.

'use strict'
const prefixer = require('.')
const instances = [
  prefixer({ prefix: 'i1', rotate: true }),
  prefixer({ prefix: 'i2', rotate: true }),
  prefixer({ prefix: 'i3', rotate: true })
instances.forEach((i) => i.pipe(process.stdout, { end: false }))
function print () {
  instances.forEach((i) => i.write(Math.random() + '\n'))
  setTimeout(print, 1000)

## API


Returns a split2 stream configure to add a prefix and a color to each line.


  • prefix: the prefix to prepend.
  • separator: to be used between the prefix and the line, defaults to :.
  • color: the chalk color to use.
  • rotate: rotate between a set of colors, with global state. Defaults to false.
  • eol: the end of line to use to reconstruct the lines. Defaults to require('os').EOL.


This project was kindly sponsored by nearForm.


Copyright Matteo Collina 2016, Licensed under MIT.