A simple and efficient command-line interface (CLI) application for managing your to-do tasks.
Built using Node.js, it provides essential task management operations like adding, listing, marking complete, and deleting tasks β all from your terminal!
- Add Tasks: Instantly add a new task to your list.
- View Tasks: List all your pending and completed tasks clearly.
- Mark as Completed: Update any task's status to completed.
- Delete Tasks: Remove specific tasks by ID.
- Persistent Storage: Tasks are saved locally in a
todos.jsonfile. - Colorful Output: Uses
chalkfor enhanced visual feedback in the terminal. - Error Handling: Gracefully handles file reading/writing issues.
- Auto Reindexing: After deletion, IDs are automatically reordered for clarity.
- Node.js β Core platform
- Commander.js β For easy CLI command parsing
- Chalk β For colorful and readable terminal output
- fs (File System module) β For reading and writing JSON data
-
Clone the repository:
git clone https://github.com/aerinpatel/CLI-todo.git cd CLI-todo -
Install dependencies:
npm install
-
Run the CLI:
node index.js
| Command | Description |
|---|---|
node index.js add "<task>" |
Add a new todo task |
node index.js list |
List all todo tasks |
node index.js check <id> |
Mark a specific task as completed |
node index.js delete <id> |
Delete a task by its ID |
-
Loading and Saving Todos:
loadTodos()readstodos.json. If it fails, it returns an empty array with a friendly error message.saveTodos(todos)writes the updated todos array back to the file, ensuring persistence.
-
Adding Tasks:
Adds a new task with anid,taskdescription, and a defaultcompleted: false. -
Listing Tasks:
Displays all tasks, differentiating completed and pending using colored indicators ([x]for done,[ ]for pending). -
Marking Completed:
Updates thecompletedflag of a task based on its ID. -
Deleting Tasks:
Deletes a task by ID, and reindexes all subsequent tasks to maintain a neat ID sequence. -
Program Setup:
Configured with.name(),.description(), and.version()using Commander.js for a professional CLI feel.
CLI-todo/
β
βββ index.js # Main CLI application file
βββ todos.json # Stores tasks persistently
βββ package.json # Project metadata and dependencies
βββ README.md # Project documentation$ node index.js add "Finish homework"
Todo added: "Finish homework"
$ node index.js list
Your Todos:
1. [ ] Finish homework
$ node index.js check 1
Todo 1 marked as completed.
$ node index.js list
Your Todos:
1. [x] Finish homework
$ node index.js delete 1
Todo with ID 1 deleted.If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request!
Would you also like me to create badges (like npm version, License, etc.) and a small demo GIF for this CLI? π
It would make your README look even more professional! π―
Let me know!