Task Manager Project Structure
Learn how to organize a Node.js CLI Task Manager project using separate files and folders.
1. What Is a Task Manager Application?
A Task Manager is an application that allows users to manage their daily activities. Users can add tasks, view saved tasks, update task details, and delete tasks when they are completed or no longer required.
In this Node.js tutorial, we are building a command-line Task Manager. Users will interact with the application through a terminal instead of a graphical interface.
todos.json. This allows
the application to keep tasks between program executions.
2. Features of the Task Manager
| Feature | Description |
|---|---|
| Add Task | Add a new task to the task list. |
| View Tasks | Display all saved tasks. |
| Update Task | Modify the details or status of a task. |
| Delete Task | Remove a task from the list. |
| Save Tasks | Store task information in a JSON file. |
3. Project Folder Structure
A well-organized project separates the main application, saved task data, and package configuration into different files.
TaskManager/
|
|-- package.json
|-- app.js
|
|-- todos.json
|
|-- README.md
Purpose of Each File
| File | Purpose |
|---|---|
package.json |
Stores project information and npm scripts. |
app.js |
Contains the application logic and CLI operations. |
todos.json |
Stores task data in JSON format. |
README.md |
Documents the project and explains how to run it. |
4. Task Manager Architecture
The following diagram explains how the user, Node.js program, and JSON file work together.
User
Selects an operation from the terminal
app.js
Processes commands and manages tasks
todos.json
Stores task information
Terminal Output
Displays the updated task information
For example, when a user adds a task, the application
receives the input, updates the task data, saves it to
todos.json, and displays a confirmation.
5. Create the Task Manager Project
Step 1: Create a Project Folder
Open a terminal and execute:
mkdir TaskManager
cd TaskManager
Step 2: Initialize the Node.js Project
Run the following command to generate a
package.json file with default settings.
npm init -y
Step 3: Create the Application File
Create a file named app.js.
console.log("Welcome to Task Manager!");
console.log("1. Add Task");
console.log("2. View Tasks");
console.log("3. Update Task");
console.log("4. Delete Task");
Step 4: Create the JSON Data File
Create todos.json and add an empty JSON array.
[]
An empty array means that no tasks have been stored yet. Later, we will save task objects inside this array.
Step 5: Run the Application
node app.js
Expected Output
Welcome to Task Manager!
1. Add Task
2. View Tasks
3. Update Task
4. Delete Task
6. How Task Data Is Stored
Each task can be represented as a JavaScript object. Multiple task objects can be stored together in a JSON array.
Example JSON Data
[
{
"id": 1,
"title": "Learn Node.js",
"completed": false
},
{
"id": 2,
"title": "Practice JavaScript",
"completed": true
}
]
In this example, each task has an ID, a title, and a
completion status. The completed property
uses a Boolean value: true means the task
is completed, while false means it is not.
Task Objects
ID, title, and completion status
JSON Array
Contains multiple task objects
todos.json
Persists task data between runs
7. Benefits of a Proper Project Structure
- Files are easy to find and maintain.
- Application logic and saved data are separated.
- JSON data can be inspected and understood easily.
- New features can be added step by step.
- The project becomes easier to test and troubleshoot.
8. Practice Task
Task: Prepare Your Project
Create a folder named TaskManager and add:
package.jsonapp.jstodos.jsonREADME.md
Initialize the project using npm init -y,
display the Task Manager menu from app.js,
and store an empty array in todos.json.
Challenge: Add a fifth menu option named
Exit and display it in the terminal.
Summary
A Node.js CLI Task Manager allows users to organize daily tasks
through a terminal. We created a project structure containing
package.json for project configuration,
app.js for application logic, and
todos.json for storing task information. We also
displayed a basic task menu and explored how task objects
can be stored in a JSON array.
This project structure provides the foundation for adding, reading, updating, deleting, and saving tasks in the next lessons at CIIT Training Institute.