DEV Community

Cover image for Appealing Console Output with Colors.js
Humjerry⚓
Humjerry⚓

Posted on • Edited on

Appealing Console Output with Colors.js

Many developers often overlook this package in the development of their APIs with Node.js. Is it worth it? Is it even necessary? Will my code not run fine if I don't have it installed? The answer is NO. However, using the colors.js package gives an appealing visual and a better console output, giving room for easy debugging process.

Start this way

1. Get the 'Colors.js' Installed
the first thing to be done is to install the package. to do this open up your terminal and run the following command:

npm install colors
Enter fullscreen mode Exit fullscreen mode

after running the command, the Node package manager (NPM) installs the package for you in a few seconds.

2. Now require the 'colors.js' in your script:
now that you have the package installed, next is to require the package into you main script. Run this line of code to achieve it

const colors = require("colors");
Enter fullscreen mode Exit fullscreen mode

the above line of code imports the 'colors.js' module, thus allowing the developer explore what it offers.

Apply colors to the console output

take this simple line of code for instance

console.log("get high paying jobs when you code in".yellow,"or keep earning little while coding in".red);
Enter fullscreen mode Exit fullscreen mode

You can "underline" and make output "bold"

by simply doing

console.log("Let the lines be underlined and bold".underline.bold);
Enter fullscreen mode Exit fullscreen mode

the "colors.js" can be used in several ways to make our console logs visually appealing. you can learn more when you visit colors.js. So many things for you to try out.

Wrap up

I really recommend the "colors.js" for Node.js console output as it helps make our output visually appealing and debugging easier and faster.

Top comments (1)

Collapse
 
humjerry profile image
Humjerry⚓

Thank you for Checking. feel free to drop your thoughts and opinions.