Changing font-color with escape codes
We can change the font color of text by using the escape code :
\x1b[3$m
Note: The ‘$’ sign can be replaced with any number between 0 to 7
Color |
Escape Code |
---|---|
Black |
\x1b[30m |
Red |
\x1b[31m |
Green |
\x1b[32m |
Yellow |
\x1b[33m |
Blue |
\x1b[34m |
Magenta |
\x1b[35m |
Cyan |
\x1b[36m |
Blue |
\x1b[37m |
Example : This example change console font color to magenta.
Javascript
console.log( '\x1b[35m%s\x1b[0m' , 'This text is magenta' ); |
Output: The escape code ‘\x1b[0m‘ at the end is to set the text color back to default
How to change Node console font color ?
To change the font color we can use the chalk module in Node as well as the ASCII characters escape codes. We will discuss how to change the font color using both the approaches in this article
Table of Content
- Changing color using chalk module
- Changing font-color with escape codes