Member-only story
How To Create Beautiful Command Line Interactions With Node.js
Inquierer.js, a must-known Node.js library
Node.js has seen a lot of competition lately. The most well-known competitor for a while has been Deno. Recently it has seen how Bun has gained a lot of traction and popularity. However, don’t be fooled into thinking that Node.js is dead just yet. It has always had many problems and controversy, but as of today, it is still a good choice to make.
Deno still has a lot of catching up to do. Its initial hype has seemed to cool off. The ecosystem of Node.js is huge, and it will take a bit more time for Deno to mature and get used. On the other hand, Bun is not yet production-ready. Although I am a big fan of Bun, Node.js will still be around for a while.
In this article, I want to exemplify the richness of the Node.js ecosystem by seeing how simple it is to create a command line interactive user interface. How can we achieve that? By using Inquirer.js. You must likely have come across it. Popular libraries like Remix or NextJs use it behind the scenes.
Installation
It is a npm dependency, so it can be installed easily by just doing the following:
npm install --save inquirerEven though commonjs modules have been the go-to for years in node, the v9 version and higher are built on native esm modules. Node has been supporting esm modules since version 12.
If you need it to run on an older node version, you can have to install it using the latest version 8.
// will install the latest 8 versions
npm install --save inquirer@^8.0.0All you need to do to start using the library is simply import it. Here’s the code to do that:
// v8 and lower
const inquirer = require('inquirer');// v9 an higher
import inquirer from 'inquirer';
Prompts
The API is quite intuitive. It all revolves around Promises, which makes it super easy to use and reason. Alternatively, we can use Rx.Observales, which is referred to as React Interface in their documentation. In this article, we will focus on the promise-based interface.

