javascriptnode.jsvisual-studio-codecolorsconsole.log

How to change console.log() output in VSCode?


I want to change color for some of my console.log() statements. Make some of them red and others green. Is there a way to do it if I use VSCode console to run my code?


Solution

  • Of course, You can do that in VScode, using a package called chalk:-

    const chalk = require('chalk');
     
    console.log(chalk.red('Hello world!')); //will turn your log into red.
    

    Can also customize the theme according to your preferences, even it supports various styles, modifiers, background colors

    const chalk = require('chalk');
     
    const error = chalk.bold.red;
    const warning = chalk.keyword('orange');
     
    console.log(error('Error!'));
    console.log(warning('Warning!'));