chalk
Chalk is the most popular library for styling terminal string output with colors and formatting in Node.js. The library provides a chainable API for applying fo…
Installation
npm install chalk
yarn add chalk
pnpm add chalk
Import
import chalk from 'chalk';
Quick Example
import chalk from 'chalk';
console.log(chalk.red.bold('Error: ') + 'Something went wrong');
console.log(chalk.green('✓ ') + 'Tests passed');
console.log(chalk.bgBlue.white(' INFO ') + ' Processing...');
console.log(chalk.hex('#FF8800')('Custom color'));About chalk
Chalk is the most popular library for styling terminal string output with colors and formatting in Node.js. The library provides a chainable API for applying foreground colors, background colors, and text modifiers (bold, italic, underline, strikethrough, dim, inverse) to strings printed to the terminal. Chalk uses ANSI escape codes that work across Windows, macOS, and Linux terminals, with automatic color support detection that gracefully disables colors when output is piped or the terminal does not support them. The API is expressive: chalk.red.bold('Error!'), chalk.bgYellow.black('Warning'), chalk.hex('#FF8800')('Custom'). Chalk supports the full spectrum of color options including named colors (red, green, blue, etc.), RGB values, hex codes, and ANSI 256 color palette. Chalk v5+ is ESM-only, while v4 supports CommonJS for backward compatibility. The library handles nested styles correctly and provides template literal support through chalk.level configuration. Chalk is used by virtually every Node.js CLI tool that produces colored output, including npm, Yarn, ESLint, Prettier, Jest, and hundreds of others. It sets the standard for terminal string styling in the JavaScript ecosystem.
Quick Facts
| Package | chalk |
| Category | Utility |
| Weekly Downloads | 200M+ |
| License | MIT |
| Install | npm install chalk |
Related Packages
picocolors is the smallest and fastest library for adding colors to terminal output, providing a lig…
Ora is an elegant terminal spinner library for Node.js that provides visual feedback during long-run…
Commander is the most popular library for building command-line interfaces in Node.js, providing a f…
Inquirer.js is a collection of common interactive command-line user interfaces for Node.js, providin…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.