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

Introduction to Node.js

Node.js allows us to run JavaScript outside the web browser. It is commonly used to build web servers, APIs, and backend applications.

In this tutorial, we will learn what Node.js is, how it works, and how to write our first Node.js program using simple examples.

What is Node.js?

Node.js is a JavaScript runtime environment. It allows us to execute JavaScript code outside a web browser.

For example, Samadhan can write JavaScript code to create a server, read files, or connect an application to a database using Node.js.

Before Node.js, JavaScript was mainly used in web browsers. Node.js made it possible to use JavaScript for backend development too.

Why Do We Use Node.js?

  • To build backend applications using JavaScript.
  • To create web servers and REST APIs.
  • To read and write files.
  • To connect applications with databases.
  • To build real-time applications such as chat applications.

How Does Node.js Work?

Look at the diagram below. It shows how JavaScript code is executed by Node.js outside the browser.

JavaScript Code

Written by Samadhan or Pradnya

↓

Code is executed using

Node.js Runtime

Executes JavaScript outside the browser

↓
Output / Application

Console output, server, API, or file operation

Your First Node.js Program

Let us write a simple program. Pradnya wants to display a welcome message and two student names in the terminal.

Step 1: Create a File

Create a file named app.js. The .js extension represents a JavaScript file.

Step 2: Write the Code

JavaScript
console.log("Welcome to Node.js!");
console.log("Student 1: Samadhan");
console.log("Student 2: Pradnya");

Step 3: Run the Program

Open the terminal in the folder containing app.js and execute:

Terminal
node app.js

Step 4: Expected Output

Output
Welcome to Node.js!
Student 1: Samadhan
Student 2: Pradnya
Explanation:
  • console.log() displays a message in the terminal.
  • app.js is the JavaScript file we created.
  • node app.js tells Node.js to execute that file.

Program Execution Flow

When Pradnya runs the command, Node.js reads the file, executes the statements, and displays the output.

1. Create app.js
↓
2. Run: node app.js
↓
3. Node.js executes the code
↓
4. Output appears in the terminal

Node.js vs Browser JavaScript

Browser JavaScript Node.js
Runs inside a web browser. Runs outside the browser.
Can interact with the webpage DOM. Provides APIs for files and operating-system tasks.
Commonly handles webpage interactions. Commonly handles servers and backend logic.
Example: button click handling. Example: creating an HTTP server.

Important Points

  • Node.js is a JavaScript runtime environment.
  • It executes JavaScript outside a web browser.
  • Node.js is commonly used for servers and APIs.
  • console.log() displays output in the terminal.
  • Use node app.js to execute the example file.

Summary

Node.js allows developers to run JavaScript outside the browser. We can use it to build servers, APIs, and backend applications. In our first program, we created app.js, executed it using node app.js, and displayed messages in the terminal.