Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Chalk Terminal string styling done right

I've had no luck in seeing any results appear in my iTerm2 while trying to use chalk which is a terminal string styling package. I followed all the steps in installing the package but I'm not seeing any colored string result appear when I run a basic console.log("hello"); in my chalk.js file.

Here is what I am doing.

#!/usr/bin/env node
var chalk = require('chalk');
chalk.blue('Hello world!');
console.log("hello");

Then in iTerm2 I run node chalk.js and I see no colored strings just plane old boring grey..

Anyone know what I'm doing wrong here?

https://www.npmjs.com/package/chalk

like image 839
brent_white Avatar asked Mar 31 '15 08:03

brent_white


People also ask

How do you use chalk in Javascript?

// Importing the chalk module const chalk=require("chalk"); // Coloring different text messages const welcome=chalk. green; const warning=chalk. red; console. log(welcome("Welcome to Tutorials Point")) console.


1 Answers

Chalk functions return a string with the appropriate ANSI escape codes.

You need to console log the result of chalk calls.

console.log(chalk.blue("Hello, world!"));

If you still don't see any color, try running with the command line argument --colors. If that still doesn't work, set an environment variable FORCE_COLOR=1.

If it still doesn't work, you're welcome to file a bug report!

like image 171
Qix - MONICA WAS MISTREATED Avatar answered Sep 23 '22 00:09

Qix - MONICA WAS MISTREATED