Node.js Chalk Module
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:
- It helps to customize the color of the output of the command-line output
- 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.