This article is a showcase of a popular node library to display colors in the console.

The gist

Here is the code you need to get started:

var colors = require('colors');

// Text color
console.log(colors.red('Love, exciting and new'));

// Invert colors (including background)
console.log(colors.inverse('Come aboard, we\'re expecting you'));

// Custom style
console.log(colors.rainbow('Love, life\'s sweetest reward'));

// Background Color
console.log(colors.bgMagenta('Let it flow, it floats back to you'));

// Combine different properties
console.log(colors.bgGreen.black('The Love Boat soon will be making another run'));


Run it and you will see the following in your console:


Don’t forget to npm install the library with:

$ npm install --save colors

String prototype

The library will also add string prototypes to simplify the code, use whichever you prefer:

// Text color
console.log(('Love, exciting and new').red);

// Invert colors (including background)
console.log(('Come aboard, we\'re expecting you').inverse);

// Custom style
console.log(('Love, life\'s sweetest reward').rainbow);

// Background Color
console.log(('Let it flow, it floats back to you').bgMagenta);

// Combine different properties
console.log(('The Love Boat soon will be making another run').bgGreen.black);

Easter Egg

The library mentions a “a secret undocumented style”. Here it is for those too lazy to look it up.