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 vs Browser JavaScript

JavaScript can run inside a web browser or outside the browser using Node.js. The language is the same, but the available features and execution environments are different.

In this lesson, we will compare both environments using simple programs, practical examples, diagrams, and their real-world uses.

1. What Is Browser JavaScript?

Browser JavaScript runs inside browsers such as Chrome, Edge, and Firefox. It is commonly used to make webpages interactive.

Examples of browser JavaScript include:

  • Handling button clicks.
  • Validating form fields.
  • Changing webpage content.
  • Displaying messages and updating the user interface.

2. What Is Node.js?

Node.js is a runtime environment that executes JavaScript outside the browser. It is commonly used for backend applications, web servers, APIs, file processing, and automation tools.

  • Creating HTTP servers.
  • Reading and writing files.
  • Building REST APIs.
  • Connecting applications to databases through suitable drivers.

3. Node.js vs Browser JavaScript

Feature Browser JavaScript Node.js
Execution environment Inside a web browser Outside the browser
Common purpose Frontend development Backend and server-side development
DOM access Usually available for webpages No browser DOM by default
File access Restricted and controlled by browser security Can use Node.js file-system APIs subject to operating-system permissions
Global object window is available in typical webpage scripts globalThis is available; Node.js also provides Node-specific globals
Common output Webpage or browser console Terminal or application response
Example APIs document, window, fetch node:fs, node:http, process
Typical use Interactive website interface Web server and REST API
Important: Some APIs, such as fetch(), are available in both modern browsers and current Node.js versions. Availability depends on the runtime and version.

4. Architecture Comparison

The diagram shows the different roles JavaScript can perform in the browser and in Node.js.

Browser Environment
JavaScript
↓
Browser APIs

DOM, window, webpage events

Webpage

Buttons, forms, and content

Node.js Environment
JavaScript
↓
Node.js APIs

Files, HTTP, process, timers

Backend Application

Server, API, file operations

5. Same JavaScript in Both Environments

Basic JavaScript syntax works in both environments. For example, variables, arithmetic, conditions, loops, and functions follow the same language rules.

Example Program

JavaScript
let firstNumber = 10;
let secondNumber = 20;

let total = firstNumber + secondNumber;

console.log("Total:", total);

This program can run in Node.js. It can also run in a browser when placed in a suitable script and viewed using the browser console.

Node.js Command

Terminal
node calculation.js

Expected Output

Output
Total: 30

Explanation: The program creates two variables, adds their values, stores the result in total, and prints it using console.log().

6. Browser JavaScript Practical Program

Let us create a webpage that displays a welcome message when a user clicks a button.

Step 1: Create index.html

HTML + JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Browser JavaScript Example</title>
</head>
<body>

    <h2>CIIT TRAINING INSTITUTE</h2>

    <button id="welcomeButton">Click Me</button>
    <p id="message"></p>

    <script>
        document
            .getElementById("welcomeButton")
            .addEventListener("click", function () {
                document.getElementById("message").textContent =
                    "Welcome to JavaScript!";
            });
    </script>

</body>
</html>

Step 2: Run the Example

  1. Save the code as index.html.
  2. Open the file in a web browser.
  3. Click the Click Me button.

Expected Result

CIIT TRAINING INSTITUTE
Click Me

After clicking the button: Welcome to JavaScript!

Program Explanation

  • document.getElementById() finds an HTML element by its ID.
  • addEventListener("click", ...) registers a function that runs when the button is clicked.
  • textContent changes the text displayed on the webpage.
Why does this work in a browser? Because the browser provides the document API, which lets JavaScript access and update the webpage DOM.

7. Node.js Practical Program

Now let us write a program that displays information in the terminal using Node.js.

Step 1: Create app.js

JavaScript
const os = require("node:os");

console.log("Welcome to CIIT TRAINING INSTITUTE");
console.log("Platform:", os.platform());
console.log("Architecture:", os.arch());

Step 2: Run the Program

Terminal
node app.js

Example Output

Output — example only
Welcome to CIIT TRAINING INSTITUTE
Platform: win32
Architecture: x64

The platform and architecture values depend on the computer. The output above is an example for a typical 64-bit Windows system.

Program Explanation

  • require("node:os") imports Node.js's built-in operating-system module.
  • os.platform() returns a platform identifier.
  • os.arch() returns the CPU architecture for the Node.js process.
  • The program prints these values in the terminal.
Important: The node:os module is provided by Node.js. It is not a standard browser API.

8. How to Choose the Right Environment

What are you building?
↓
Webpage Interaction

Use browser JavaScript for buttons, forms, and DOM updates.

↓
Server or Backend

Use Node.js for HTTP servers, APIs, and backend logic.

Many applications use both: browser JavaScript for the interface and Node.js for backend services.

9. Common Mistakes

  • Trying to use document directly in a normal Node.js script without a DOM implementation.
  • Assuming all browser APIs are available in Node.js.
  • Assuming Node.js can access every local file without permissions.
  • Assuming Node.js and browser JavaScript use different programming languages.

Learning at CIIT TRAINING INSTITUTE

Understanding the difference between frontend and backend JavaScript helps learners plan and develop complete web applications.

Skills Students Can Practise
  • Writing and debugging JavaScript programs.
  • Building interactive webpages.
  • Running JavaScript programs using Node.js.
  • Understanding browser and server responsibilities.
  • Connecting frontend applications with backend APIs.

These fundamentals provide a foundation for learning Express.js, REST APIs, databases, authentication, and full-stack development.

Important Points

  • JavaScript is the programming language in both environments.
  • Browsers provide webpage APIs such as document.
  • Node.js provides APIs for files, networking, and system tasks.
  • Some APIs, including fetch(), can exist in both environments.
  • One application can use browser JavaScript and Node.js together.

Summary

Browser JavaScript is commonly used to make webpages interactive, while Node.js is commonly used for backend applications and servers. Both execute JavaScript, but the available APIs differ. Understanding these differences helps students at CIIT TRAINING INSTITUTE build a foundation for full-stack web development.