node-console-badge

Lightweight, zero-dependency helper to print clean, custom status badges in Node.js terminals.


Keywords
console, badge, terminal, cli, log, logging, status, ansi, color, colors, pretty, output
License
MIT
Install
npm install node-console-badge@1.0.0

Documentation

node-console-badge

Print clean status badges in Node.js terminals. No dependencies.

const badge = require('node-console-badge')

badge.success('Deployed to production (v1.2.0)')
badge.error('Build failed: tests/unit.test.js:42')
badge.warn('Disk usage at 90% - consider cleanup')
badge.info('Server listening on :3000')
[ SUCCESS ] Deployed to production (v1.2.0)
[ ERROR ] Build failed: tests/unit.test.js:42
[ WARN ] Disk usage at 90% - consider cleanup
[ INFO ] Server listening on :3000

Install

npm install node-console-badge

Usage

Presets

const badge = require('node-console-badge')

badge.success('Deployed to production')
badge.error('Build failed')
badge.warn('Disk usage at 90%')
badge.info('Server listening on :3000')
badge.debug('cache miss for key: user:42')

Presets show a symbol (, , , , ) when colors are active. Disable with { symbol: false }.

Custom labels

badge('DB', 'Migrated 3 tables', { color: 'magenta' })
badge('CI', 'Running pipeline #128', { color: 'cyan', symbol: '▶' })
badge('AUTH', 'Token refreshed', { color: 'blue', styles: 'italic' })
[ DB ] Migrated 3 tables
[ ▶ CI ] Running pipeline #128
[ AUTH ] Token refreshed

Filled style

Renders the label as a bold white block on a colored background:

const deploy = badge.create('DEPLOY', { color: 'green', filled: true })
deploy('Packaging assets')
deploy('Pushing to registry', { symbol: false })

badge.error('Fatal: connection refused', { filled: true, styles: 'bold' })
✔ DEPLOY  Packaging assets
 DEPLOY  Pushing to registry

Reusable badges

const db = badge.create('DB', { color: 'magenta' })
db('connected')
db('query took 12ms', { width: 8 }) // align labels: [ DB   ]

Get the string without printing

const line = badge.format('WARN', 'careful', { color: 'yellow', styles: 'bold' })

API

  • badge(label, message, options?) - print a custom badge
  • badge.format(label, message, options?) - same, but return the string
  • badge.create(label, options?) - returns a reusable (message, extraOptions?) => void
  • badge.success | error | warn | info | debug(message, options?) - presets
  • badge.supportsColor(stream?) - returns 0, 1, or 3

Options

Option Type Default Description
color string 'cyan' Label color: named (green) or hex (#22c55e)
bg string 'cyan' Background color for filled style
filled boolean false Render label as a filled colored block
pad number 1 Padding around the label
width number 0 Min width of the label area (aligns badges)
symbol string | boolean | null preset Prefix symbol; true uses the preset symbol
styles string | string[] bold, dim, italic, underline
stream object stdout Stream probed for color support
level number auto Force color level (0, 1, 3)

Colors: black, red, green, yellow, blue, magenta, cyan, white, gray, or a 6-digit hex like #22c55e (truecolor only).

Color detection follows the usual rules: off when piped or not a TTY, off with NO_COLOR, on with FORCE_COLOR=1, and truecolor when COLORTERM is truecolor.

License

MIT