How to use Chalk style string style done right

Iโ€™m not lucky that some results will appear in iTerm2, trying to use the chalk, which is a package of styles with a terminal line. I followed all the steps to install the package, but I donโ€™t see any colored string result appearing when the base console.log("hello"); launched console.log("hello"); in my chalk.js file.

That's what I'm doing.

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

Then in iTerm2 I ran node chalk.js and I don't see that the colored lines are just plain old boring gray ones.

Does anyone know what I'm doing wrong here?

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

+5
source share
1 answer

The chalk functions return a string with the corresponding ANSI escape codes.

You need to block the log of the results of ringing tones.

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

If you still cannot see the color, try running with the --colors command line --colors . If this still does not work, set the environment variable FORCE_COLOR=1 .

If it still does not work, you can write a bug report !

+8
source

Source: https://habr.com/ru/post/1216513/


All Articles