Skip to content

Getting Started

Installation

bash
npm install console-marker

Node.js ≥ 20 when running server-side. In the browser, import directly — no runtime requirements.

Quick start

ts
import marker from 'console-marker';

console.log(marker.red('Hello world'));
console.log(marker.bold.green('Build complete'));
console.log(marker.bgBlue.white.bold(' SUCCESS '));

CommonJS

marker ships dual ESM + CJS — no config needed.

js
const marker = require('marker');
console.log(marker.red('Hello world'));

Named imports

Tree-shakeable single-style imports:

ts
import { red, bold, green, bgBlue, cyan } from 'console-marker';

console.log(red('error'));
console.log(bold(green('ok')));

Browser DevTools

In a browser, use the .log() / .warn() / .error() / .info() / .debug() methods on any builder. They automatically emit %c CSS styling to DevTools instead of ANSI escape codes.

ts
import marker from 'console-marker';

marker.red.bold.log('build failed')
// → console.log('%cbuild failed%c', 'color:#cd3131;font-weight:bold', '')

marker.green.log`${count} tests passed`
marker.bgRed.white.error`FATAL: ${message}`

The same code works in Node — it emits ANSI strings there. No environment checks needed.

See Browser console for the full guide.

TypeScript

Types are bundled. No @types/marker needed.

ts
import marker, { type Builder } from 'console-marker';

function highlight(text: string): string {
  return marker.bold.yellow(text);
}

Released under the MIT License.