Master Node.js From Scratch

Clear, interactive, and structured Node.js lessons designed for beginners and developers.

COURSE SYLLABUS
1. Introduction to Node.js
Introduction to Node.js What Is Node.js? Node.js Architecture Features of Node.js Node.js vs Browser JavaScript Node.js Use Cases
2. Installation and Setup
Installation Introduction LTS and Current Versions npm Setup Environment Setup Verify Installation Node.js REPL
3. Node.js Fundamentals
Fundamentals Introduction Running JavaScript Global Objects Process Object Command-Line Arguments Environment Variables
4. JavaScript Basics
JavaScript Basics Introduction Variables: var, let and const JavaScript Data Types Comparison and Logical Operators If, Else If, Else and Switch Loops and Iteration Functions and Arrow Functions JavaScript Array Methods
5. Node.js Modules
Modules Introduction CommonJS Modules ES Modules Export and Import Built-in Modules Creating Custom Modules Path Module OS Module
6. Working with JSON
JSON Introduction JSON Syntax JSON.stringify() JSON.parse() JSON Array of Objects JSON User Database
7. Node Package Manager
npm Introduction package.json Installing Packages Dependencies and DevDependencies npm Scripts Package Versions and Semantic Versioning npm init and Project Setup
8. File System
File System Introduction Reading Files Writing Files Appending Files Deleting Files Working with Directories
9. CLI Applications
CLI Applications Introduction Command-Line Input Task Manager Project Structure Reading todos.json Adding, Updating and Deleting Tasks Saving Tasks to JSON
10. Events and EventEmitter
Events Introduction EventEmitter Registering Events Emitting Events Removing Event Listeners Custom Events
11. Asynchronous Programming
Async Programming Introduction Callbacks Promises async and await setTimeout() and setInterval() Event Loop and Non-Blocking I/O
12. Native HTTP Module
HTTP Module Introduction Creating an HTTP Server Handling Requests Sending Responses HTTP Request Methods Status Codes and Headers Handling POST Request Body Parsing Incoming JSON Products JSON API
13. Express.js
Express.js Introduction Installing Express Creating an Express Server Request and Response Objects Route Parameters and Query Strings Serving Static Files
14. Express Middleware
Middleware Introduction Built-in Middleware Application-Level Middleware Router-Level Middleware Custom Middleware Error-Handling Middleware
15. REST API Development
REST API Introduction GET Endpoints POST Endpoints PUT and PATCH Endpoints DELETE Endpoints Request Validation and API Responses
16. Database Integration
Database Introduction MySQL Integration MongoDB Integration Database CRUD Operations Database Queries and Filtering Connection Management
17. Authentication and Authorization
Authentication Introduction Password Hashing User Registration User Login JWT Authentication Authorization and Protected Routes
18. Advanced Node.js
Advanced Node.js Introduction Error Handling Debugging Node.js Applications Streams Buffers Performance and Security

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.

Remember: We will store task information in a JSON file named 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.
Note: These files are part of the planned project structure. You will create the application logic and JSON data in the following lessons.

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:

Terminal
mkdir TaskManager
cd TaskManager
Step 2: Initialize the Node.js Project

Run the following command to generate a package.json file with default settings.

Terminal
npm init -y
Step 3: Create the Application File

Create a file named app.js.

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.

todos.json
[]

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
Terminal
node app.js
Expected Output
Output
Welcome to Task Manager!
1. Add Task
2. View Tasks
3. Update Task
4. Delete Task
Result: You have created the initial Task Manager project structure and displayed its menu. The menu is currently static; interactive operations will be implemented in the upcoming lessons.

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
todos.json
[
    {
        "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.json
  • app.js
  • todos.json
  • README.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.