Build a CLI Tool

CLI tools are command-line programs.

Node.js is often used for project scripts and developer tools.

Goal

Build a CLI that greets a user:

node greet.js Asha

Output:

Hello, Asha

Basic solution

const name = process.argv[2]

if (!name) {
  console.error('Please provide a name')
  process.exit(1)
}

console.log(`Hello, ${name}`)

What this teaches

Improvements

Add options:

node greet.js --name Asha --uppercase

Then parse flags manually or with a package.

Interview angle

Explain that Node CLI tools use process.argv to read command-line input, process.exit for status codes, and filesystem/process APIs to automate tasks.