commander
: This helps us to build the CLI tool.chalk
: This makes messages in the terminal colorful and easy to read.inquirer
: This lets us ask the user for input.ora
: This makes the terminal show nice spinning animations.
# create package.json
npm init --yes
# install dependencies
npm i commander inquirer chalk ora mongoose nanoid dotenv
# remove
"main": "index.js"
# add
"exports": "./index.js",
"type": "module",
node ./db/connectDB.js
node ./commands/addTask.js
node ./commands/deleteTask.js
node ./commands/readTask.js
node ./commands/updateTask.js
Add bin property. The "bin" property in the package.json file enables you to specify commands that become globally accessible once your package is installed.
"bin": {
"todo": "index.js"
}
You can start using the tool by installing it globally
npm i -g .
Here are commands you can use to operate the tool
# Create a new task
todo add
# Read all your pending tasks
todo read
# Update a specific task
todo update
# Delete a task
todo delete
# check version
todo --version
todo -V
# display help for commands
todo --help
todo -h