
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Node.js Chalk Module
The chalk module is a third-party library that can be used for styling of texts. It allows the users to create their own themes in a Node.js project.
This module helps the users to customize the response messages with different colors as per the preferences.
It also improves the readability by providing colors and makes it easier to detect warnings and errors.
Installation
npm install chalk
Example 1
Create a file with the name "chalk.js" and copy the following code. After creating the file, use the command "node chalk.js" to run this code as shown in the example below −
// Importing the chalk module const chalk=require("chalk"); // Coloring different text messages console.log(chalk.green("Welcome to Tutorials Point")) console.log(chalk.red.underline("Welcome to Tutorials Point")) console.log(chalk.red.underline.bold("Welcome to Tutorials Point"))
Output
Example 2
Let's take another example
// Importing the chalk module const chalk=require("chalk"); // Coloring different text messages const welcome=chalk.green; const warning=chalk.red; console.log(welcome("Welcome to Tutorials Point")) console.log(welcome("Success !!!")) console.log(warning("Error - An unknown error occurred !")) console.log(warning("Warning - Exception occurred !"))
Output
Advertisements