Node.js chalk Command Line Output Colorful

Adding Color to Command Line Output Using Node.js Chalk

This article introduces how to colorize command line output in Node.js using the utility library 'chalk', which allows you to change the color of command line output.

Shou Arisaka
1 min read
Nov 9, 2025

This article introduces how to colorize command line output in Node.js using the utility library โ€œchalkโ€, which allows you to change the color of command line output.

chalk/chalk: ๐Ÿ– Terminal string styling done right

sudo npm install chalk

Usage example

yuis@yuis:~/share04/_tmp/tmp$ node
> const chalk = require('chalk'); const log = console.log;
undefined
> log(chalk.blue('Hello') + ' World' + chalk.red('!'));
Hello World!
undefined
>

Image

log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));

// Nest styles
log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));

// Nest styles of the same type even (color, underline, background)
log(chalk.green(
    'I am a green line ' +
    chalk.blue.underline.bold('with a blue substring') +
    ' that becomes green again!'
));

Image

Share this article

Shou Arisaka Nov 9, 2025

๐Ÿ”— Copy Links