Gor Gor - 1 month ago 26
Node.js Question

node js terminal color

How can I set terminal font color in node js. I found some modules, but there have limited colors, I want to use any color.

For example.
Something like this.

console.log("text", "#87a213");


On this question`s answer are 3 modules, but in these modules colors are limited. I need to print with any color.

Thank You.

Answer

You can use ansi-256-colors package. But it does not support any color. But it supports wide range of colors.

To install:

npm install --save ansi-256-colors

To use:

console.log(colors.fg.getRgb(2,3,4) + colors.bg.getRgb(4,4,4) + 'Hello world!' + colors.reset);