As developers, we kind of live with CLI tools. From git to cloud shells — we are using these tools everywhere. So, it’s time to make your own. We’ll use Heroku’s great oclif framework in the process.

What’s oclif?

It’s an open framework to build CLI tools quickly, and it’s provided by the well-known Heroku.

What’s gonna be built?

We’ll make a todo list command that can have four actions:

  • Add a new task
  • View all tasks
  • Update task
  • Remove a task

Initialize our project

Oclif can generate two types of projects —

  1. Projects that have one command.
  2. Projects that might have multiple commands, including nested ones.

In this article, we’re gonna need a multiple commands project, so let’s generate it:

npx oclif multi todocli

Running this command and following the instructions will initialize a fresh project named todocli inside the current directory.

Now, let’s go inside the directory and run help…

#node-js

How to build a CLI tool in NodeJS
3 Likes27.25 GEEK