Skip to content

dazecoop/nodejs-console-colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Node.js console-colors

const consoleColors = {
  // Common
  reset: '\x1b[0m',
  dim: "\x1b[2m",
  underscore: "\x1b[4m",
  reverse: "\x1b[7m",

  // Text 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",

  // Background colors
  BgBlack: "\x1b[40m",
  BgRed: "\x1b[41m",
  BgGreen: "\x1b[42m",
  BgYellow: "\x1b[43m",
  BgBlue: "\x1b[44m",
  BgMagenta: "\x1b[45m",
  BgCyan: "\x1b[46m",
  BgWhite: "\x1b[47m",
}

Usage

You should aim to always use reset after each log.
See example.js for demo.

console.log(`\n${consoleColors.dim} Dimmed text ${consoleColors.reset}`);
console.log(`\n${consoleColors.cyan} Cyan text ${consoleColors.reset}`);
console.log(`\n${consoleColors.black}${consoleColors.BgGreen} Black text, green background ${consoleColors.reset}`);
console.log(`\nRegular, ${consoleColors.white}${consoleColors.BgRed}red background${consoleColors.reset}, back to regular`);
console.log("\n");

image

About

Examples & usage of Node console.log coloring

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published