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

CLI Applications Introduction

Learn how to create and run Command-Line Interface (CLI) applications using Node.js.

1. What Is a CLI Application?

CLI stands for Command-Line Interface. A CLI application is a program that users interact with by typing commands or entering information in a terminal instead of clicking buttons in a graphical user interface.

Node.js allows developers to create CLI applications using JavaScript. These applications can perform tasks such as reading files, managing data, processing commands, and automating repetitive work.

Remember: A CLI application takes input through the terminal, processes it using program logic, and displays the result in the terminal.

2. Examples of CLI Applications

Application Purpose
Task Manager Add, view, update, and delete tasks.
File Manager Create, read, rename, and delete files.
Calculator Perform mathematical calculations.
Student Record System Manage student information through commands.
Automation Tool Automate repetitive development tasks.

3. How Does a CLI Application Work?

A CLI application follows a simple process: the user provides input, the application processes that input, and the result is displayed in the terminal.

User

Enters a command or information

↓
Terminal

Receives the user's input

↓
Node.js Application

Processes the input using JavaScript

↓
Output

Displays the result in the terminal

4. Requirements for Creating a CLI Application

Before creating a Node.js CLI application, make sure you have:

  • Node.js installed on your computer.
  • A code editor such as Visual Studio Code.
  • A terminal such as Command Prompt or PowerShell.
  • Basic knowledge of JavaScript.

To check whether Node.js and npm are installed, run:

Terminal
node --version
npm --version

Example output:

Output
v22.x.x
10.x.x

The displayed version numbers may differ depending on your installation.

5. Create Your First CLI Application

Let's create a simple CLI application that displays a welcome message in the terminal.

Step 1: Create a Project Folder

Open your terminal and run:

Terminal
mkdir MyFirstCLI
cd MyFirstCLI
Step 2: Create a JavaScript File

Create a file named app.js inside the project folder.

Step 3: Write the Code
app.js
console.log("Welcome to My First CLI Application!");
console.log("Node.js makes CLI development easy.");
Step 4: Run the Application

Execute the following command from the project folder:

Terminal
node app.js

Expected Output:

Output
Welcome to My First CLI Application!
Node.js makes CLI development easy.
What happened? Node.js executed the JavaScript file and displayed both messages in the terminal using console.log().

6. CLI vs GUI

CLI GUI
Command-Line Interface Graphical User Interface
Uses text commands and terminal input. Uses windows, buttons, menus, and icons.
Often useful for automation and developer tools. Often useful for applications with visual controls.
Example: Running node app.js. Example: Clicking a button in a desktop application.

7. Important Commands

Command Purpose
node --version Displays the installed Node.js version.
npm --version Displays the installed npm version.
node app.js Runs the app.js JavaScript file.
mkdir MyFirstCLI Creates a project directory.
cd MyFirstCLI Moves into the project directory.

8. Practice Task

Task: Create a Student Welcome CLI

Create a file named student.js and display:

Expected Output
Welcome to CIIT Training Institute!
Student Name: Rahul
Course: Node.js
Learning Mode: Practical

Hint: Use four console.log() statements and run the file using node student.js.

Summary

A CLI application is a program that users interact with through a terminal by entering commands or information. Node.js allows developers to create CLI applications using JavaScript. We created our first CLI application using console.log() and executed it with the node app.js command.

CLI applications are useful for task management, file operations, automation, and developer tools. At CIIT Training Institute, these concepts help learners build practical Node.js applications.