Skip to content
Related Articles

Related Articles

NodeJS Chalk Module
  • Last Updated : 17 Feb, 2021

Chalk module in Node.js is the third-party module that is used for styling the format of text and allows us to create our own themes in the node.js project.

Advantages of Chalk Module:

  1. It helps to customize the color of the output of the command-line output
  2. It helps to improve the quality of the output by providing several color options like for warning message red color and many more

Chalk Module: https://www.npmjs.com/package/chalk

Installing Module:

npm install chalk



Project Structure:

Example 1:

index.js




// Importing module
const chalk=require("chalk");
  
// Printing the text
console.log(chalk.red("aayush"))
console.log(chalk.red.underline("aayush"))
console.log(chalk.red.underline.bold("GFG"))

Run index.js file using below command:

node index.js

Output: This will be the console output.

Example 2: Defining own themes.

index.js




// Importing chalk module
const chalk=require("chalk");
  
// Creating theme
const warning=chalk.red;
  
// Printing theme text
console.log(warning("Restricted Zone"));
const welcome=chalk.green
console.log(welcome("GFG"))

Run index.js file using below command:

node index.js

Output: This will be the console output.


Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :