a blog for those who code

Friday 11 July 2014

Colors Module in Nodejs

In this post we will show what is Colours Module in Nodejs and whats the usage of it. The Colors module is one of the simplest module in Nodejs. It is used to provide different style and color effects to the "console.log" output.
To use Colors module first we have to install it using Npm.

$ npm install colors

Now, we can start the Node.js (REPL) and do some coloring to console.

> console.log("Hello, How are you today?" .rainbow.bold);

The style only applies for one message, we need to apply another style for another message.

Color Modules is useful when we need to provide specific formatting for various events, such as providing one color for errors in one module, another for warning and another one for success.

How can we achieve this, lets see

> colors.setTheme({
..... warnMessage : 'yellow',
..... errorMessage : 'red',
..... successMessage : 'green'
..... });
> console.log("Success".successMessage)

Like this we can use the color theme in our console.

Please Like and Share the Blog, if you find it interesting and helpful.

No comments:

Post a Comment