That is, how to make the text that is sent to a terminal bold, italic, give it colors, etc? The answer is using ANSI Escape Sequences. Using the Control Sequence Introducer group of ANSI Escape Sequences, we can style the text that appears on a terminal, on the terminals that support ANSI Escape Sequences.
For example, let's say that we want to make a portion of the text that we print bold. We can do it as follows:
// ANSI escape character
const ESC = '\x1B';
// Control Sequence Introducer
const CSI = `${ESC}[`;
// Select Graphic Rendition (SGR) sequences
const BOLD = `${CSI}1m`;
const RESET = `${CSI}0m`;
// Some text to test the ANSI Escape Sequences
console.log(`${BOLD}Hello.${RESET} How are you?`);
The output should be "Hello. How are you?", with the "Hello." part of the string styled as bold on terminals that support ANSI escape sequences.
Note that escape sequences embedded in object properties won't have any effect.