Node.js Chalk Module
Last Updated :
07 Oct, 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:
- 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
const chalk=require( "chalk" );
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
const chalk=require( "chalk" );
const warning=chalk.red;
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
Share your thoughts in the comments
Please Login to comment...