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

Node.js Features

Node.js provides powerful features for building fast, scalable, and efficient backend applications using JavaScript.

At CIIT TRAINING INSTITUTE, students can learn these features through practical programs and real-world application examples. This knowledge helps them understand how modern backend systems work.

1. What Are Node.js Features?

Features are the capabilities or characteristics of a technology. Node.js provides tools and programming models that help developers create web servers, APIs, file-processing applications, and more.

For example, a shopping website may receive many requests to view products. Node.js can handle I/O operations asynchronously so that the application does not have to wait synchronously for each operation to finish.

Learning objective: Understand the major Node.js features, write working programs, examine their output, and learn when these features are useful.

2. Important Features of Node.js

Feature Simple Explanation Example Use
Asynchronous I/O Allows other work to continue while supported I/O operations are pending. Reading files and calling APIs.
Event-Driven Responds to events and executes associated callbacks. HTTP requests and event listeners.
Non-Blocking I/O Avoids synchronously waiting for supported I/O operations. File and network operations.
V8 Engine Executes JavaScript code. Running application logic.
NPM Provides access to packages and project scripts. Using Express.js in an application.
Cross-Platform Node.js applications can run on supported operating systems. Windows, Linux, and macOS.
Scalability Supports applications that handle many I/O operations. Web servers and REST APIs.

3. Asynchronous Programming

Asynchronous programming allows a program to start an operation and continue doing other work while that operation is pending. When the result is ready, the program can process it.

This is especially useful for operations such as reading files, accessing databases, and communicating with external services.

Practical Program

The following program schedules a timer and continues executing other statements without synchronously waiting for the timer.

JavaScript — async-example.js
console.log("Application started");

setTimeout(() => {
    console.log("Background task completed");
}, 2000);

console.log("Application is doing other work");

Run the Program

Terminal
node async-example.js

Expected Output

Output
Application started
Application is doing other work
Background task completed

Explanation

  1. The first statement prints Application started.
  2. setTimeout() schedules a callback for approximately two seconds later.
  3. JavaScript continues to the next statement and prints Application is doing other work.
  4. When the timer callback becomes eligible and can run, it prints Background task completed.
Remember: The timer delay is not an exact execution-time guarantee. Asynchronous programming does not automatically make CPU-heavy JavaScript run in parallel.

4. Event-Driven Architecture

In event-driven programming, a program responds when a particular event occurs. An event listener waits for an event, and a callback runs when that event is emitted.

Node.js provides the EventEmitter class for creating and handling custom events.

Program Using EventEmitter

JavaScript — events-example.js
const EventEmitter = require("node:events");

const eventEmitter = new EventEmitter();

eventEmitter.on("studentRegistered", (studentName) => {
    console.log(studentName + " registered successfully");
});

console.log("Waiting for registration event");

eventEmitter.emit("studentRegistered", "CIIT Student");

Run the Program

Terminal
node events-example.js

Expected Output

Output
Waiting for registration event
CIIT Student registered successfully

Explanation

  • require("node:events") imports the built-in events module.
  • new EventEmitter() creates an event emitter.
  • on() registers a listener for the studentRegistered event.
  • emit() emits the event and passes the student name to the listener.

5. How Asynchronous Operations Work

This simplified diagram shows how an application can continue executing JavaScript while an asynchronous operation is pending.

1. Start an I/O operation

Example: request a file

↓
2. Continue other JavaScript work

Do not synchronously wait for the result

↓
3. Operation completes

The result becomes available

↓
4. Process the result

Run the callback or continue the Promise

6. Non-Blocking I/O

I/O means Input/Output. Reading a file, receiving a network request, and communicating with a service are common I/O operations.

A non-blocking API lets JavaScript continue executing while the operation is pending. This can improve responsiveness when an application has many I/O operations.

Practical File Reading Program

First, create a file named message.txt containing:

message.txt
Welcome to CIIT TRAINING INSTITUTE

Create another file named file-example.js in the same directory.

JavaScript — file-example.js
const fs = require("node:fs");

console.log("Starting file operation");

fs.readFile("message.txt", "utf8", (err, data) => {
    if (err) {
        console.error("Unable to read the file:", err.message);
        return;
    }

    console.log("File content:", data);
});

console.log("JavaScript continues executing");

Run the Program

Terminal
node file-example.js

Expected Output

Output
Starting file operation
JavaScript continues executing
File content: Welcome to CIIT TRAINING INSTITUTE

Explanation

  • The program imports the built-in file-system module.
  • fs.readFile() starts an asynchronous file read.
  • JavaScript continues to the next statement without synchronously waiting for the file read.
  • When the operation completes, the callback checks for an error and displays the file content.
Note: The shown order is the expected order for this example under normal conditions. File operations depend on the environment, and asynchronous completion time can vary.

7. Cross-Platform Support

Node.js is available for multiple operating systems, including Windows, Linux, and macOS.

Developers can often use the same JavaScript application across these platforms. However, operating-system-specific file paths, permissions, and external dependencies may require adjustments.

Operating System Typical Use
Windows Local development and application testing.
Linux Many production servers and cloud deployments.
macOS Local development and testing.

8. NPM and Packages

NPM is commonly used to install packages, manage project dependencies, and run scripts. It is distributed with standard Node.js installations.

Packages let developers reuse existing code instead of building every feature from scratch. Express is one example of a package used to build web applications and APIs.

Useful Commands

Terminal
node --version
npm --version
npm init -y

What Do These Commands Do?

  • node --version displays the installed Node.js version.
  • npm --version displays the installed npm version.
  • npm init -y creates a default package.json file in the current directory.

9. Scalability

Scalability is the ability of an application to handle increased demand by using available resources effectively and, when needed, adding more resources or application instances.

Node.js can be suitable for applications with many concurrent I/O operations, such as REST APIs, chat systems, and notification services.

However, scalability depends on application design, database performance, caching, deployment, and the amount of CPU work. Node.js alone does not guarantee high performance.

10. Node.js in a Real Application

Consider a training portal where students view courses and submit assignments. A simplified request flow looks like this.

Student / Browser

Requests course information

↓
Node.js Backend

Processes the request and application logic

↓
Database or External Service

Provides the requested data

↓
Response to Student

Displays the course information

This is a simplified request flow. A real application may include authentication, validation, caching, and additional services.

11. Advantages of Node.js

  • JavaScript on the backend: Developers can use JavaScript for frontend and backend code.
  • Efficient I/O: Asynchronous APIs help avoid blocking while waiting for many I/O operations.
  • Reusable packages: NPM provides packages for common application requirements.
  • Broad platform support: Applications can run on supported operating systems.
  • Useful ecosystem: Developers can build APIs, servers, and real-time applications.

12. Limitations of Node.js

  • CPU-heavy JavaScript can block the main JavaScript thread.
  • Poorly handled asynchronous errors can make applications unreliable.
  • Dependency versions and package security require attention.
  • Performance depends on application design and the workload.
Best practice: Handle errors, validate incoming data, keep dependencies updated, and avoid long-running CPU-heavy tasks on the main JavaScript thread.

Learn Node.js at CIIT TRAINING INSTITUTE

Learning Node.js through practical exercises helps students move from basic JavaScript to backend development.

What Students Can Learn
  • Node.js fundamentals and runtime architecture.
  • Asynchronous programming and EventEmitter.
  • File handling, NPM, and reusable packages.
  • HTTP servers and REST API development.
  • Database integration and CRUD operations.
  • Practical application development and debugging.

Learning benefit: These skills help learners build a foundation for backend development and understand concepts used in real-world projects.

Important Points

  • Node.js uses the V8 engine to execute JavaScript.
  • Asynchronous I/O helps the application continue while I/O is pending.
  • EventEmitter provides a way to create and handle events.
  • NPM helps manage packages and project scripts.
  • Node.js supports multiple operating systems.
  • CPU-heavy tasks can still block the main JavaScript thread.

Summary

Node.js provides asynchronous I/O, event-driven programming, a JavaScript runtime powered by V8, and an ecosystem of packages managed with tools such as npm. These features make it useful for many backend applications. At CIIT TRAINING INSTITUTE, students can develop these concepts through practical programs and progressively build complete applications.