Blog

Command Line Interface (CLI) with NodeJS

If you are a developer, there is a good chance that you are looking at a command line interface (CLI) every day… Almost every modern framework has its own CLI as a result of the tendency to automate frequent tasks (boilerplate generator, migrations, etc.).

Cloud providers such as DigitalOcean, Amazon Web Services (AWS), etc. have their own use cases for CLI, mainly for managing infrastructure using Application Programming Interface (API).

My team works on a project called VivifyScrum. It’s an in-house project that we also use to track progress while we are working on it, so we are using VivifyScrum while we are making it.

I’ve seen recently that competition already has command line tools that give you the possibility to manage data using just command line interface (CLI). It’s not anything groundbreaking but having the possibility to manage data through command line interface is really nice. That is why I’ve decided to make one for VivifyScrum CLI called vivify-cli.

This command line tool will probably not be widely used by users who are more accustomed to a graphical user interface, but who knows?

After all, today’s browsers are memory monsters. :)

How it’s made

I’ve started making it using the NodeJS stack. First of all, I needed a library to make development as easy and fast as possible. There are many available options but probably the most widely known one is yargs. It’s a really useful library if you want to make any kind of command line tool.

I also needed something to give a better user experience to people while they wait for the result of their actions and I chose ora for this, an elegant terminal spinner.

Confirmations, questions, choices, and others can be implemented really fast with inquirer. This package is widely used by the community, so I think it makes for a good starting point.

If you need the possibility to persist some data locally, I recommend using the library called configstore which I used on VivifyScrum CLI. Implementation is really straightforward and easy.

Of course, there are more possibilities if you need to style some output color or wrap text, but with these four packages above you can cover all basic functionalities for your command line interface.

I would encourage you to take a look at vivify-cli GitHub repo for more info.

Happy coding!