Node.js CLI To-Do List
Build a to-do list for the terminal with Node.js: run node todo.js add "Buy milk", node todo.js list, node todo.js done 2 or node todo.js remove 3, and your tasks are saved in a JSON file so they're still there next time. The list shows each task's number and whether it's done, in color. It's a great first Node.js project: you'll learn reading command-line arguments with process.argv, reading and writing files with the fs module, working with JSON, organizing code into small functions and modules, handling errors, and writing tests with Node's built-in test runner.
- Estimate
- ~5.5h
- Steps
- 5
- Completed by
- 0
- Proposed by
- codeseed.app
Node.js · fs module
Project roadmap
- 01
Read the command
~1hCreate a project with npm init and a todo.js file. Read the command and its arguments from process.argv.slice(2), and print a usage message listing all commands (add, list, done, undo, remove and clear-done) when the command is missing or unknown, exiting with code 1. Done when: running node todo.js without arguments prints the usage.
- 02
Save tasks to a file
~1hWrite loadTasks and saveTasks in a separate module using fs.readFileSync and fs.writeFileSync with JSON.parse and JSON.stringify. Each task has an id, text, done and createdAt. When the file doesn't exist, start with an empty list; when it's broken, stop with a clear message instead of overwriting it. Save by writing a temporary file and renaming it. Done when: tasks saved by one run load in the next.
- 03
Add the commands
~1.5hImplement add (joining the remaining arguments into the text, and refusing empty text), list (numbered, with [x] or [ ], and --all to include finished tasks, otherwise only open ones), done N, undo N, remove N and clear-done. Check that N is a number and exists, with a clear message otherwise. Done when: every command works and changes are kept between runs.
- 04
Add colors
~0.5hInstall a small color package such as picocolors, and show finished tasks in grey with a green check and open tasks in the normal color, plus a summary line such as 2 of 5 done. Turn colors off when the output isn't a terminal. Done when: the list is colored in the terminal and plain when piped to a file.
- 05
Write tests
~1.5hWrite tests with Node's built-in test runner (node --test) for the task functions and the file module, using a temporary folder: adding, completing and removing, invalid numbers, a missing file, a broken file, and saving then loading. Done when: npm test passes.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack