I found this answer above (https://stackoverflow.com/a/41407246/4808079) very useful, but incomplete. If you only ever wanted to color something once, I guess it'd be fine, but I think sharing it in a runnable functional form is much more applicable to real life use cases.
const Color = { 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", FgGray: "\x1b[90m", BgBlack: "\x1b[40m", BgRed: "\x1b[41m", BgGreen: "\x1b[42m", BgYellow: "\x1b[43m", BgBlue: "\x1b[44m", BgMagenta: "\x1b[45m", BgCyan: "\x1b[46m", BgWhite: "\x1b[47m", BgGray: "\x1b[100m", } function colorString(color, stringmsg) { return `${color}${stringmsg}${Color.Reset}`; } function colorLog(color, ...args) { console.log(...args.map( (it) => typeof it === "string" ? colorString(color, stringit) : it )); } Use it like this:
colorLog(Color.FgYellow, "Some Yellow text to console log", { someObj: true }); console.log([ colorString(Color.FgRed, "red"), colorString(Color.FgGreen, "green"), colorString(Color.FgBlue, "blue"), ].join(", "));