2

For my project I need to be able to print to the NodeJS console in RGB. In most browser I can use console.log('%c Oh my heavens! ', 'background: #222; color: #bada55'); but that doesn't work in NodeJS.

I have looked at the colors module but that doesn't seem to support custom colors.

It is possible to achieve this?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Jordan Baron
  • 3,752
  • 4
  • 15
  • 26

2 Answers2

1

NodeJS console not work this way. You can use terminal colors like this:

console.log('\x1b[36m%s\x1b[0m', 'I am cyan'); //cyan 
console.log('\x1b[33m%s\x1b[0m', stringToMakeYellow); //yellow

There is little more about terminal colors: https://askubuntu.com/q/558280

vovchisko
  • 2,049
  • 1
  • 22
  • 26
0

There is a Node module called Tynt- and it brings easy coloring to the Node.js console.

var tynt = require("tynt");

console.log(tynt.Blue("Your blue text here!") + "  " + tynt.Red("Your red text here!"))

If you want a list of colors, you can find them here:

github.com/muzzen/tynt

Thanks for reading!