Vasanth Developer
9 JavaScript Libraries To Create The Coolest CLIs

9 JavaScript Libraries To Create The Coolest CLIs

4 min readOct 10, 2022On Dev

Lets look at libraries that help us to create the coolest command line applications.

JavaScript is a great tool to build incredible CLIs that can be easily installed and provide great user experience. I've personally used all the 9 libraries we'll see below 👇

1. itivrutaha

itivrutaha

A super fancy way of console.log() that supports emoji, outputs in colors and can even write to a file. It is specially designed for usage in CLIs with support for advanced features like multiple log instances with different contexts.

Support for colors and emoji are handled properly and with flexible themeing options and most importantly, it is created by me 😉

2. Conf

import Conf from 'conf'
 
const config = new Conf()
 
config.set('unicorn', '🦄')
config.get('unicorn')
// => '🦄'
 
// dot-notation to access nested properties
config.set('foo.bar', true)
console.log(config.get('foo'))
// => { bar: true }

Different operating systems save config files differently, With conf you don't need to worry about where to store configuration keys for your CLI program.

It is highly configurable and supports advanced features like migration, encryption and storing in different data formats with a sleek API.

3. Commander

commander help

It is the most popular and feature rich command line argument parser with extensive docs, easy-to-use API and automatic help generation. I have tried to use several libraries but I always come back to it.

Advanced features like variadic options, custom option parsing, sub commands are all available. Personally I find it's help messages a bit bland, so I created rupa which outputs help messages in a colorful way 👇

rupa help message

4. Listr2

listr2

Lets you create really cool task lists that can be easily understood by the user while conveying the progress of the work. You can create sub-tasks, conditionally run tasks or skip them or new add tasks on the fly.

For non-interactive environments, Listr2 handles verbose and silent logging perfectly 👌

5. Execa

import { execa } from 'execa'
 
const { stdout } = await execa('echo', ['unicorns'])
 
// piping the child process stdout to the parent
execa('echo', ['unicorns']).stdout.pipe(process.stdout)

It is a wrapper around the built-in child_process module to make it easy to run shell commands inside our CLIs.

With improved Windows support, bigger buffer for stdio, excellent docs and a promise based interface it is the goto library to run system commands inside CLIs.

6. CLI Table 3

cli table 3

Render out tabular data in the terminal to output human-readable data in a concise way with this module.

This module is a balance between stablity and features as it is very popular, once you choose to use it, you'll forgot about it 😄

7. Inquirer

inquirer prompts

Add interactive prompts to your CLIs ✨

It is extendable and stable with lots of big projects depending on it. Several types of prompts are pre-built with good docs. Using inquirer along with listr2 and itivrutaha can create a superb user experience.

In addition to that, for taking complicated user input through a text editor, checkout read-file-input from me 😊

8. ASCII Art

ascii art

Lets you create a cool artwork that can be shown when the CLI starts. It is more extensive compared to lot of popular alternatives with advanced features like support for custom figlet fonts, color profile support and much more.

9. Pkg

Lets you bundle your amazing CLI into a single binary file that doesn't require Node.js to be installed on the user's computer. It also protects from tampering the code as JavaScript can be easily modified.

Several other alternatives exist like caxa, nexe but this one is well maintained by Vercel.

Conclusion

Providing good user experience is equally important for CLIs as much as offering speed and functionality. With these 9 npm modules, JavaScript CLIs can be polished to give the best user experience along great functionality.

Thank you 😊

Share this page