Skip to content

Build a To-Do List CLI with File Storage

Programming Node.js Difficulty 1/5

Beginning of the lesson

Build a To-Do List CLI with File Storage

Turn small commands into a real tool you can use every day

Big Idea: In this mini-project we combine two things you already know -- reading the process.argv command line and reading/writing files with the fs module -- to build a real to-do list program. You will type commands like node todo.js add "Buy milk" in the terminal, and your program will remember your tasks in a JSON file, even after you close it.
By the end you will be able to:
  • read a command and its argument from process.argv,
  • load tasks from a JSON file and save them back,
  • build four actions: add, list, done, and delete,
  • handle the very first run, when the file does not exist yet,
  • put it all together into one small, tidy program.

1. What are we building?

Imagine a sticky note on your fridge where you write down chores: "Buy milk", "Walk the dog", "Finish homework". When a chore is done, you cross it out. When it no longer matters, you throw the note away. Our program is that fridge note, but it lives in your terminal.

Analogy. Think of the program as a small helper at a coat check. You walk up and say a short command -- "add this", "show my list", "mark number 2 done" -- and the helper writes everything in a little notebook kept in a drawer. The notebook is our JSON file. Every time you come back, the helper opens the same notebook, so nothing is forgotten.

Here is what using the finished tool looks like in the terminal:

node todo.js add "Buy milk"
node todo.js add "Walk the dog"
node todo.js list
node todo.js done 0
node todo.js delete 1

Each line is one command. The word right after todo.js (add, list, done, delete) tells the program what to do. That is the whole idea of a CLI -- a command-line interface.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers