Getting started

Let’s start by creating a brand new npm package

mkdir my-script

cd my-script

npm init

NPM will ask some questions. After that, we need to install some packages.

npm install --save chalk figlet inquirer shelljs

What these packages do:

chalk — Terminal string styling done right

— Terminal string styling done right figlet — Figlet is a program for making large letters out of ordinary text

— Figlet is a program for making large letters out of ordinary text inquirer — A collection of common interactive command line user interfaces

— A collection of common interactive command line user interfaces shelljs — Portable Unix shell commands for Node.js

index.js file

Now create a index.js file with the following content:

Planning the CLI

it’s always good to plan what a CLI needs to do before writing any code.

This CLI will do just one thing: Create a file.

It should ask a couple of questions and after that, show a success message with the created file path.

The questions are: what is the filename and what is the extension.

The first function is the script introduction. Let’s use chalk and figlet to get the job done.

Now it’s time to write a function that asks questions.

Notice the constants FILENAME and EXTENSIONS that came from inquirer .

The next step is to create the file.

And last but not least, show the success message along with the file path.