Compilation of Libraries Supporting CLI Application Development for Node.js

Compilation of Libraries Supporting CLI Application Development for Node.js

Daily short news for you
  • For over a week now, I haven't posted anything, not because I have nothing to write about, but because I'm looking for ways to distribute more valuable content in this rapidly exploding AI era.

    As I shared earlier this year, the number of visitors to my blog is gradually declining. When I looked at the statistics, the number of users in the first six months of 2025 has dropped by 30% compared to the same period last year, and by 15% compared to the last six months of 2024. This indicates a reality that users are gradually leaving. What is the reason for this?

    I think the biggest reason is that user habits have changed. They primarily discover the blog through search engines, with Google being the largest. Almost half of the users return to the blog without going through the search step. This is a positive signal, but it's still not enough to increase the number of new users. Not to mention that now, Google has launched the AI Search Labs feature, which means AI displays summarized content when users search, further reducing the likelihood of users accessing the website. Interestingly, when Search Labs was introduced, English articles have taken over the rankings for the most accessed content.

    My articles are usually very long, sometimes reaching up to 2000 words. Writing such an article takes a lot of time. It's normal for many articles to go unread. I know and accept this because not everyone encounters the issues being discussed. For me, writing is a way to cultivate patience and thoughtfulness. Being able to help someone through my writing is a wonderful thing.

    Therefore, I am thinking of focusing on shorter and medium-length content to be able to write more. Long content will only be used when I want to write in detail or delve deeply into a particular topic. So, I am looking for ways to redesign the blog. Everyone, please stay tuned! 😄

    » Read more
  • CloudFlare has introduced the pay per crawl feature to charge for each time AI "crawls" data from your website. What does that mean 🤔?

    The purpose of SEO is to help search engines see the website. When users search for relevant content, your website appears in the search results. This is almost a win-win situation where Google helps more people discover your site, and in return, Google gets more users.

    Now, the game with AI Agents is different. AI Agents have to actively seek out information sources and conveniently "crawl" your data, then mix it up or do something with it that we can't even know. So this is almost a game that benefits only one side 🤔!?

    CloudFlare's move is to make AI Agents pay for each time they retrieve data from your website. If they don’t pay, then I won’t let them read my data. Something like that. Let’s wait a bit longer and see 🤓.

    » Read more
  • Continuing to update on the lawsuit between the Deno group and Oracle over the name JavaScript: It seems that Deno is at a disadvantage as the court has dismissed the Deno group's complaint. However, in August, they (Oracle) must be held accountable for each reason, acknowledging or denying the allegations presented by the Deno group in the lawsuit.

    JavaScript™ Trademark Update

    » Read more

Issue

Hello readers of 2coffee.dev. I wonder if anyone here has been using command-line applications (CLI)? If so, why did you choose it over a graphical user interface (GUI)? If I remember correctly, I have written a few articles about the process of creating some applications for myself. Honestly, for me, there are many cases where CLI proves to be much more useful.

Recalling my early days of switching from Windows to Linux, specifically Ubuntu. I have cursed countless times about this damn operating system. The interface is ugly, hard to use, and everything requires typing commands; how can anyone remember all those lines? It’s not like Windows is good. The interface is intuitive and easy to use. You just need to look to know where to click, everything is visible.

True to the saying, "what you hate, fate gives you". In the end, I became "addicted" to this command-line typing without even noticing. There must be a reason for this addiction; it helps me approach problems faster. Instead of moving the mouse around, I can just type, which is much quicker. Not to mention that many software applications are provided in CLI form, which in turn leads to the creation of management tools, allowing us to easily install our favorite applications with just a single command.

That was also the inspiration for me to tackle problems using CLI. Most of it is to help manage my blog. In the early days of exploring, there were so many new things that I didn’t know. It took a lot of time to learn while doing. Understanding that psychology, today I will compile some libraries that I know from my previous learning process. These libraries not only help you create quality applications but also make them more appealing to users.

Oh! All of these are Node.js libraries. If you are using other platforms like Go, Rust… I’m sure there are similar libraries. You just need to search based on the ideas of the libraries below.

Let's get started!

Framework

First, we need to talk about the framework; this is where you structure your CLI application. Imagine the framework helps shape, structure the code, and features to fit the nature of the CLI.

Notice that we often see command-line applications using a format like this:

$ mycli image --resize 512:512 /path/to/image

With mycli being the application name, image is almost a function, and the flag --resize is typically used to specify additional attributes. Finally, /path/to/image points to the data that needs to be processed.

If you are familiar with Node.js, you will see that CLI is quite similar to the node command, while the following parameters can easily be captured through the process.argv variable.

$ node index.js image --resize 512:512 /path/to/image
// console.log(process.argv); ['node', 'index.js', 'image', '--resize', '512:512', '/path/to/image']

In other words, just parsing process.argv is sufficient to classify and call the corresponding functions with the used parameters. At that point, the application is no different from a CLI.

yargs and commander are two foundational libraries to help us parse parameters as mentioned above. They provide very basic functions to serve as a foundation for other libraries.

oclif is one example. This tool helps us create powerful CLI applications by optimizing the workflow. oclif defines everything, from the directory structure to the help commands generated for new features. All you need to do is focus on writing the logic. After a "build" step, oclif produces a complete CLI application, including usage instructions without requiring you to do many additional steps.

Configuration File

In an application, apart from the default configurations or configurations hardcoded in the code, sometimes user configuration is still needed.

For example, you provide the user with the ability to set the input/output paths for files after processing. This option needs to be saved somewhere for future use. The easiest way is to create a text file and store all the information in it. Or more professionally, you can use the cosmiconfig library.

cosmiconfig is a library that automatically fetches configuration files into your application. cosmiconfig supports many formats such as .json, .yaml, .yml... After loading, cosmiconfig puts all the values into a variable that you can use in your application.

Input

Input is an essential part of CLI applications; besides receiving user data through flags like --resize, there are many other optimized ways.

inquirer is a library that provides many ways to receive user data. For example, displaying a text input box, yes/no questions, or select options... each time a certain command is typed.

Output

Have you ever used a CLI application that shows beautiful "loading" effects during interaction? Or lines of text with various colors to highlight important information? There are many libraries to help us achieve this.

ora is a library that creates beautiful "loading" effects. These effects are often used to signal to users that processing is underway and they need to wait. ora provides many different "spinning" shapes. Additionally, you can combine it with text to create continuous messages on the screen, indicating the progress of the ongoing process.

progress helps you create "downloading" effects using a combination of ASCII characters.

Sometimes you will need to draw a table to display information for output, cli-table3 is very suitable for this. Or if you simply want to enclose content in "boxes", boxen is a perfect choice.

Additionally, you can combine with chalk to style the text. This is a great library to change colors, add effects like "bold", "dim", "italic"... to highlight content. Or if you prefer a "rainbow" effect, gradient-string is unbeatable.

Utils

In addition to the main libraries mentioned above, there are still many other utility libraries that CLI can use.

open helps us open something like images, web addresses, or even applications. This library proves useful when we need the assistance of an external application that the CLI cannot handle.

clipboardy helps read data from the clipboard or issue commands to copy anything you want.

shelljs is used to run any other command-line programs through the shell.

And many other libraries that I cannot list all here.

Conclusion

Above is a compilation of some libraries that assist in creating a CLI application for Node.js. As a CLI enthusiast, I have researched and applied quite a few useful libraries in my applications. What about you? Are you using any additional tools? Please leave a comment for me and everyone to know. Thank you!

Premium
Hello

Me & the desire to "play with words"

Have you tried writing? And then failed or not satisfied? At 2coffee.dev we have had a hard time with writing. Don't be discouraged, because now we have a way to help you. Click to become a member now!

Have you tried writing? And then failed or not satisfied? At 2coffee.dev we have had a hard time with writing. Don't be discouraged, because now we have a way to help you. Click to become a member now!

View all

Subscribe to receive new article notifications

or
* The summary newsletter is sent every 1-2 weeks, cancel anytime.

Comments (0)

Leave a comment...