Node.js – Chalk 模組
chalk 模組是一個第三方庫,可用於給文字新增樣式。它允許使用者在 Node.js 專案中建立自己的主題。
此模組可幫助使用者使用不同的顏色自定義響應訊息,以滿足自己的喜好。
它還透過提供顏色來提高可讀性,並使檢測警告和錯誤變得更加容易。
安裝
npm install chalk
示例 1
建立一個名為“chalk.js”的檔案,並複製以下程式碼。建立檔案後,使用命令“node chalk.js”來執行此程式碼,如下例所示 −
// 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"))輸出

示例 2
我們再舉一個例子
// 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 !"))輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP