Stream ANSI terminal output to an HTML format.


A through-stream that converts terminal output to HTML.

$ npm install ansi-html-stream

Or, if you want to install the CLI tool:

$ [sudo] npm install -g ansi-html-stream

Take this example to pipe a log of NPM's install command to an HTML file:

$ npm install browserify --color always 2&>1 | ansi-html > browserify.html

And an equivalent from Node:

var spawn = require('child_process').spawn
  , ansi = require('ansi-html-stream')
  , fs = require('fs')
var npm = spawn('npm', ['install', 'browserify', '--color', 'always'], {
    cwd: process.cwd()
var stream = ansi({ chunked: false })
  , file = fs.createWriteStream('browserify.html', 'utf8')
stream.pipe(file, { end: false })
stream.once('end', function() {

There are a few options you can pass to the stream too:

  • classes: Use classes instead of inline styles for formatting.
  • theme: Override the styling for particular ANSI codes. See colors.js for two examples.
  • chunked: Ensure that each chunk's elements are self-contained - closes any open <span>s at the end and reopens them on the next chunk. Defaults to false.