ansi-colors
Lightweight, fast Node.js library for adding ANSI color and style codes to terminal strings. Used by Gulp.js, Mocha, and many popular CLI tools. Zero dependencies, CommonJS compatible, and faster than chalk in many benchmarks. Supports colors, bright colors, background colors, and text styles. Respects NO_COLOR and FORCE_COLOR environment variables.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Zero-dependency terminal coloring — no network access, no security concerns.
⚡ Reliability
Best When
CommonJS Node.js projects needing lightweight, zero-dependency terminal coloring compatible with Gulp/Mocha ecosystem.
Avoid When
You're already using chalk or need tagged template literal syntax.
Use Cases
- • Style terminal output in Node.js CLI tools with zero dependencies: colors.red('error'), colors.green('success')
- • Add colors to build tool output in Gulp.js, Mocha, or custom build scripts
- • Chain styles: colors.bold.red.underline('critical error') for compound styling
- • Implement conditional color support using colors.enabled toggle for non-TTY environments
- • Replace chalk in CommonJS projects that need faster startup time and zero dependencies
Not For
- • ESM-only projects where chalk v5 is preferred
- • Tagged template literal syntax — ansi-colors uses function call syntax, not chalk`{red text}` format
- • Browser environments — ANSI codes only work in terminals
Interface
Authentication
Library — no auth needed.
Pricing
MIT licensed open source library.
Agent Metadata
Known Gotchas
- ⚠ Import name collision: const colors = require('ansi-colors') — 'colors' is also a popular (controversial) npm package; use a distinct alias if both are in the codebase
- ⚠ colors.enabled defaults to true even without TTY — set colors.enabled = Boolean(process.stdout.isTTY) for proper TTY detection
- ⚠ Measuring styled string length requires colors.unstyle() to remove ANSI codes before using string.length
- ⚠ Chaining order matters: colors.bold.red is different from colors.red.bold — the last specified becomes the outermost style
- ⚠ ESM import requires explicit .cjs extension or CommonJS interop — ansi-colors v4 is CommonJS and may need configuration in ESM projects
- ⚠ ansi-colors does not support 256-color or true color (24-bit) — only standard 16 ANSI colors are supported
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for ansi-colors.
Scores are editorial opinions as of 2026-03-06.