building ascii art for the command line with node

2020-07-07

 | 

~1 min read

 | 

148 words

I was digging through the source code of the Serverless CLI recently when I came across this little nugget that I thought was really cool - an asciiGreeting method:

lib/classes/CLIs.js
  asciiGreeting() {
    let art = '';
    art = `${art} _______                             __${os.EOL}`;
    art = `${art}|   _   .-----.----.--.--.-----.----|  .-----.-----.-----.${os.EOL}`;
    art = `${art}|   |___|  -__|   _|  |  |  -__|   _|  |  -__|__ --|__ --|${os.EOL}`;
    art = `${art}|____   |_____|__|  \\___/|_____|__| |__|_____|_____|_____|${os.EOL}`;
    art = `${art}|   |   |             The Serverless Application Framework${os.EOL}`;
    art = `${art}|       |                           serverless.com, v${version}${os.EOL}`;
    art = `${art} -------'`;

    this.consoleLog(chalk.yellow(art));
    this.consoleLog('');
  }

I thought this was a great example of how to use template literals. I also hadn’t heard of the OS module before - so that was a nice introduction — the EOL method standardizes the end of line across operating systems:

The operating system-specific end-of-line marker.

  • \n on POSIX
  • \r\n on Windows


Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!