I want to change the console text color in my node console (command prompt) when using console.info()
or console.error()
. I know you can change text color with some backslashes and color codes, but is there a way to make it default some colors? Like console.error()
could default to red, and console.warn()
could default to yellow. Any help is appreciated, thanks!
Asked
Active
Viewed 579 times
0

johng3587
- 103
- 9
1 Answers
2
I suppose you could overwrite those console
functions with your own, with your desired color:
// Save a reference to the original functions
const { info, error } = console;
console.info = (arg) => {
info.call(console, `\x1b[33m${arg}\x1b[0m`);
};
console.error = (arg) => {
info.call(console, `\x1b[31m${arg}\x1b[0m`);
};
And so on. Use whatever colors you want.

CertainPerformance
- 356,069
- 52
- 309
- 320
-
Sorry, I should have mentioned this is from a node.js console, or command prompt. – johng3587 Dec 12 '21 at 03:36
-
Same thing works, just overwrite the built-in functions with your own. It's not a great idea (overwriting built-ins never is), but it's possible. – CertainPerformance Dec 12 '21 at 03:41
-
Alrighty, Ill try that, thanks! – johng3587 Dec 12 '21 at 04:09