Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

JavaScriptbeginnercliAI generated

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

  1. 01

    Read the command

    ~1h

    Create 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.

  2. 02

    Save tasks to a file

    ~1h

    Write 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.

  3. 03

    Add the commands

    ~1.5h

    Implement 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.

  4. 04

    Add colors

    ~0.5h

    Install 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.

  5. 05

    Write tests

    ~1.5h

    Write 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.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~5.5h · 5 steps

Tech stack

Node.jsfs module