Open In App

Node.js Chalk Module

Last Updated : 07 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads