xxxxxxxxxx
// Download the npm package "colors"
// npm i colors
var colors = require("colors");
console.log("Hello World".blue);
// output: Hello World (Its blue btw lmao)
xxxxxxxxxx
console.log('%cconsole.log', 'color: green;');
console.info('%cconsole.info', 'color: green;');
console.debug('%cconsole.debug', 'color: green;');
console.warn('%cconsole.warn', 'color: green;');
console.error('%cconsole.error', 'color: green;');
xxxxxxxxxx
console.log('\x1b[36m%s\x1b[0m', 'I am cyan'); //cyan
console.log('\x1b[33m%s\x1b[0m', stringToMakeYellow); //yellow
Colors reference
Reset = "\x1b[0m"
Bright = "\x1b[1m"
Dim = "\x1b[2m"
Underscore = "\x1b[4m"
Blink = "\x1b[5m"
Reverse = "\x1b[7m"
Hidden = "\x1b[8m"
FgBlack = "\x1b[30m"
FgRed = "\x1b[31m"
FgGreen = "\x1b[32m"
FgYellow = "\x1b[33m"
FgBlue = "\x1b[34m"
FgMagenta = "\x1b[35m"
FgCyan = "\x1b[36m"
FgWhite = "\x1b[37m"
BgBlack = "\x1b[40m"
BgRed = "\x1b[41m"
BgGreen = "\x1b[42m"
BgYellow = "\x1b[43m"
BgBlue = "\x1b[44m"
BgMagenta = "\x1b[45m"
BgCyan = "\x1b[46m"
BgWhite = "\x1b[47m"
xxxxxxxxxx
colors = {
reset: '\033[0m',
//text color
black: '\033[30m',
red: '\033[31m',
green: '\033[32m',
yellow: '\033[33m',
blue: '\033[34m',
magenta: '\033[35m',
cyan: '\033[36m',
white: '\033[37m',
//background color
blackBg: '\033[40m',
redBg: '\033[41m',
greenBg: '\033[42m',
yellowBg: '\033[43m',
blueBg: '\033[44m',
magentaBg: '\033[45m',
cyanBg: '\033[46m',
whiteBg: '\033[47m'
}
console.log('\033[31m this is red color on text');
console.log('\033[0m this is reset');
console.log('\033[41m this is red color on background');
xxxxxxxxxx
/**
* @param {string} text text to return
* @param {string} color enums: [black, red, green, yellow, blue, magenta, cyan, white]
* @returns colored text
*/
const colorConsoleText = (text, color = 'black') => {
const colors = {
black: "\x1b[30m",
red: "\x1b[31m",
green: "\x1b[32m",
yellow: "\x1b[33m",
blue: "\x1b[34m",
magenta: "\x1b[35m",
cyan: "\x1b[36m",
white: "\x1b[37m",
console_color: '\x1b[0m'
}
const coloredText = `${colors[color]}${text}${colors.console_color}`
return coloredText
}
xxxxxxxxxx
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
Run code snippetHide results
xxxxxxxxxx
console.log('%c My txt ', 'My css');
// Example
console.log('%c Hello world ', 'background: #222; color: #bada55');
xxxxxxxxxx
const styles = ['color: green', 'background: yellow'].join(';');
const message = 'Some Important Message Here';
// 3. Using the styles and message variable
console.log('%c%s', styles, message);
xxxxxxxxxx
console.log(
'Nothing here %cHi Cat %cHey Bear', // Console Message
'color: blue',
'color: red', // CSS Style
);