colors in node js console

const chalk = require('chalk');

console.log(chalk.blue('Hello world!')); console.log(chalk.red('Hello world!')); console.log(chalk.green('Hello world!')); console.log(chalk.yellow('Hello world!'));

  • First, import the 'chalk' module using the require() function.
  • Then, use the chalk module to apply colors to the text in the console by calling the desired color function (e.g., chalk.blue, chalk.red, chalk.green, chalk.yellow) and passing the text you want to display within the parentheses of the function.
  • Finally, use console.log() to display the colored text in the Node.js console.