0% found this document useful (0 votes)
20 views127 pages

Playlist Link

Uploaded by

Dmdhinesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views127 pages

Playlist Link

Uploaded by

Dmdhinesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 127

Playlist Link

NodeJS
Complete Course
Introduction to NodeJS
1. Pre-requisites
2. What is NodeJS
3. NodeJs Features
4. JavaScript on Client
5. JavaScript on Server
6. Client Code vs Server Code
7. Other uses of NodeJs
8. Server architecture with NodeJs
JS is required for NodeJS
React is recommended before NodeJS
2.What is NodeJS

1. JavaScript Runtime: Node.js is an open-source,


cross-platform runtime environment for executing
JavaScript code outside of a browser.
2. NodeJs is a JavaScript in a different environment means
Running JS on the server or any computer.
3. Built on Chrome's V8 Engine: It runs on the V8 engine,
which compiles JavaScript directly to native machine
code, enhancing performance.
4. V8 is written in C++ for speed.
5. V8 + Backend Features = NodeJs
2.What is NodeJS
1. Design: Features an event-driven,
non-blocking I/O model for efficiency.
2. Full-Stack JavaScript: Allows using
JavaScript on both server and client
sides.
3. Scalability: Ideal for scalable network
applications due to its architecture.
4. Versatility: Suitable for web, real-time
chat, and REST API servers.
3. NodeJs Features
(Added)

1. Non-blocking I/O: Designed to perform non-blocking operations


by default, making it suitable for I/O-heavy operations.
2. Networking Support: Supports TCP/UDP sockets, which are
crucial for building lower-level network applications that
browsers can’t handle.
3. NodeJs Features
(Added)

1. File System Access: Provides APIs to read and write files directly,
which is not possible in browser environments for security
reasons.
2. Server-Side Capabilities: Node.js enables JavaScript to run on the
server, handling HTTP requests, file operations, and other
server-side functionalities.
3. Modules: Organize code into reusable modules using require().
3. NodeJs Features
(Removed)

1. Window Object: The global window object, which is part of web


browsers, is absent in Node.js.
2. DOM Manipulation: Node.js does not have a built-in Document Object
Model (DOM), as it is not intended to interact with a webpage's
content.
3. BOM (Browser Object Model): No direct interaction with things like
navigator or screen which are part of BOM in browsers.
3. NodeJs Features
(Removed)

Web-Specific APIs: APIs like localStorage, sessionStorage,


and browser-based fetch are not available in Node.js.
4. JavaScript on Client

1. Displays Web Page: Turns HTML code into what you


see on screen.
2. User Clicks: Helps you interact with the web page.
3. Updates Content: Allows changes to the page using
JavaScript.
4. Loads Files: Gets HTML, images, etc., from the
server.
5. JavaScript on Server
1. Database Management: Stores, retrieves, and manages
data efficiently through operations like CRUD (Create,
Read, Update, Delete).
2. Authentication: Verifies user identities to control access to
the system, ensuring that users are who they claim to be.
3. Authorization: Determines what authenticated users are
allowed to do by managing permissions and access
controls.
4. Input Validation: Checks incoming data for correctness,
completeness, and security to prevent malicious data entry
and errors.
5. Session Management: Tracks user activity across various
requests to maintain state and manage user-specific
settings.
5. JavaScript on Server
6. API Management: Provides and handles interfaces for
applications to interact, ensuring smooth data exchange and
integration.
7. Error Handling: Manages and responds to errors effectively to
maintain system stability and provide useful error messages.
8. Security Measures: Implements protocols to protect data from
unauthorized access and attacks, such as SQL injection and
cross-site scripting (XSS).
9. Data Encryption: Secures sensitive information by encrypting
data stored in databases and during transmission.
10. Logging and Monitoring: Keeps records of system activity to
diagnose issues and monitor system health and security.
6. Client Code vs Server Code
1. User/client can’t access server code directly.
2. Client must raise requests for particular APIs to
access certain features or data.
3. Environment Access: Server-side JavaScript
accesses server features like file systems and
databases.
4. Security: Server-side code can handle sensitive
operations securely, while client-side code is
exposed and must manage security risks.
5. Performance: Heavy computations are better
performed on the server to avoid slowing down
the client.
6. Client Code vs Server Code
6. Resource Utilization: Servers generally offer more
powerful processing capabilities than client
devices.
7. Data Handling: Server-side can directly manage
large data sets and database interactions, unlike
client-side JavaScript.
8. Asynchronous Operations: Server-side JavaScript is
optimized for non-blocking I/O to efficiently
manage multiple requests.
9. Session Management: Servers handle sessions and
user states more comprehensively.
10. Scalability: Server-side code is designed to scale
and handle requests from multiple clients
7. Other uses of NodeJs
1. Local Utility Scripts: Automates tasks and
processes files locally, like using shell scripts
but with JavaScript.
2. Internet of Things (IoT): Develops server-side
applications for IoT devices, managing
communications and data processing.
3. Scripting for Automation: Automates
repetitive tasks in software development
processes, such as testing and deployment.
7. Other uses of NodeJs

Real-Time Applications: Efficiently manages real-time data


applications, such as chat apps and live updates, using
WebSockets.
7. Other uses of NodeJs

Desktop Applications: Creates cross-platform desktop


applications using frameworks like Electron.
7. Other uses of NodeJs
Build Tools: Powers build processes
for front-end technologies using
tools like:
• Webpack
• Grunt
• Gulp
• Browserify
• Brunch
• Yeoman
8. Server architecture with NodeJs

Nodejs server will:


1. Create server and listen to incoming requests
2. Business logic: validation, connect to db, actual processing of data
3. Return response HTML, JSON, CSS, JS
Revision
• Click to edit Master text styles
1. Pre-requisites
• Second level
• Third level
2. What is NodeJS
• Fourth level
• Fifth level

3. NodeJs Features
4. JavaScript on Client
5. JavaScript on Server
6. Client Code vs Server Code
7. Other uses of NodeJs
8. Server architecture with NodeJs
2. Installation of NodeJS
1. What is IDE
2. Need of IDE
3. MAC Setup
• Install latest Node & VsCode
4. Windows Setup
• Install latest Node & VsCode
5. Linux Setup
• Install latest Node & VsCode
6. VsCode (Extensions and Settings)
7. Executing first .js file
8. What is REPL
9. Executing Code via REPL
2.1 What is IDE
1. IDE stands for Integrated
Development Environment.
2. Software suite that
consolidates basic tools
required for software
development.
3. Central hub for coding,
finding problems, and testing.
4. Designed to improve
developer efficiency.
2.2 Need of IDE
1. Streamlines development.
2. Increases productivity.
3. Simplifies complex tasks.
4. Offers a unified
workspace.
5. IDE Features
1. Code Autocomplete
2. Syntax Highlighting
3. Version Control
4. Error Checking
2.3 MAC Setup
• Click to edit Master text styles
• Second level
• Third level
• Fourth level
• Fifth level
2.3 MAC Setup
(Install latest Node)
Search Download NodeJS
2.3 MAC Setup
(Install VsCode)
• Click to edit Master text styles
Search VS Code on Google
• Second level
• Third level
• Fourth level
• Fifth level
2.4 Windows Setup
• Click to edit Master text styles
• Second level
• Third level
• Fourth level
• Fifth level
2.4 Windows Setup
(Install latest Node)
Search Download NodeJS
2.4 Windows Setup
(Install VsCode)
Search
• Click toVS
editCode
Master on
text Google
styles
• Second level
• Third level
• Fourth level
• Fifth level
2.5 Linux Setup
2.5 Linux Setup
(Install latest Node)
Search Download NodeJS
2.5 Linux Setup
(Install VsCode)
Search
• Click toVS
editCode
Master on
text Google
styles
• Second level
• Third level
• Fourth level
• Fifth level
2.6 VsCode
(Extensions and Settings)

1. Prettier (Format on Save)


2. Line Wrap
3. Tab Size from 4 to 2
2.7 Executing first .js file

1. Streamlines Node Command: Use node filename.js to


execute a JavaScript file in the Node.js environment.
2. Require Syntax: Use require('module') to include built-in
or external modules, or other JavaScript files in your
code.
3. Modular Code: require helps organize code into reusable
modules, separating concerns and improving
maintainability.
4. Caching: Modules loaded with require are cached,
meaning the file is executed only once even if included
multiple times.
2.8 What is REPL

1. Streamlines Interactive Shell: Executes


JavaScript code interactively.
2. Quick Testing: Ideal for testing and
debugging code snippets on the fly.
3. Built-in Help: Offers help commands via
.help.
4. Session Management: Supports saving
(.save) and loading (.load) code sessions.
5. Node.js API Access: Provides direct access
to Node.js APIs for experimentation.
6. Customizable: Allows customization of
prompt and behaviour settings.
2.9 Executing Code via REPL
Revision

1. • Click toisedit
What IDE Master text styles
• Second level
2. Need• Third
of level
IDE
• Fourth level
3. MAC Setup • Fifth level
• Install latest Node & VsCode
4. Windows Setup
• Install latest Node & VsCode
5. Linux Setup
• Install latest Node & VsCode
6. VsCode (Extensions and Settings)
7. Executing first .js file
8. What is REPL
9. Executing Code via REPL
3. First Node Server
1. How DNS Works?
2. How Web Works?
3. What are Protocols?
4. Node Core Modules
5. Require Keyword
6. Creating first Node Server
3.1 How DNS Works?
1. Domain Name Entry: User types a domain (e.g.,
www.example.com) into the browser.
2. DNS Query: The browser sends a DNS query to resolve
the domain into an IP address.
3. DNS Server: Provides the correct IP address for the
domain.
4. Browser Connects: The browser uses the IP to connect
to the web server and loads the website.
3.1 How DNS Actually Works?
1. Root DNS: Acts as the starting point for DNS resolution. It
directs queries to the correct TLD server (e.g., .com, .org).
2. TLD (Top-Level Domain) DNS: Handles queries for specific
top-level domains (e.g., .com, .net) and directs them to the
authoritative DNS server (e.g., Verisign for .com, PIR for .org)
3. Authoritative DNS: Contains the actual IP address of the
domain and answers DNS queries with this information.(e.g.,
Cloudflare, Google DNS).
3.2 How Web Works?
1. Client Request Initiation: The client (browser) initiates a
network call by entering a URL.
2. DNS Resolution: The browser contacts a DNS server to
get the IP address of the domain.
3. TCP Connection: The browser establishes a TCP
connection with the server's IP address.
4. HTTP Request: The browser sends an HTTP request to
the server.
5. Server Processing: The server processes the request and
prepares a response.
6. HTTP Response: The server sends an HTTP response back
to the client.
7. Network Transmission: The response travels back to the
client over the network.
8. Client Receives Response: The browser receives and
interprets the response.
9. Rendering: The browser renders the content of the
response and displays it to the user.
3.3 What are Protocols?
Http (HyperText Transfer Protocol):
● Facilitates communication between a web browser and a server to
transfer web pages.
● Sends data in plain text (no encryption).
● Used for basic website browsing without security.
HTTPS (HyperText Transfer Protocol Secure):
● Secure version of HTTP, encrypts data for secure communication.
● Uses SSL/TLS to encrypt data.
● Used in online banking, e-commerce.
TCP (Transmission Control Protocol):
● Ensures reliable, ordered, and error-checked data delivery over the
internet.
● Establishes a connection before data is transferred.
3.4 Node Core Modules
1. Built-in: Core modules are included
with Node.js installation.
2. No Installation Needed: Directly
available for use without npm
install.
3. Performance: Highly optimized for
performance.
3.4 Node Core Modules
1. fs (File System): Handles file operations like reading and
writing files.
2. http: Creates HTTP servers and makes HTTP requests.
3. https: Launch a SSL Server.
4. path: Provides utilities for handling and transforming file
5. paths.os: Provides operating system-related utility methods
and properties.
6. events: Handles events and event-driven programming.
7. crypto: Provides cryptographic functionalities like hashing and
encryption.
8. url: Parses and formats URL strings.
3.5 Require Keyword
1. Purpose: Imports modules in Node.js. Syntax:
2. Caching: Modules are cached after the const moduleName = require('module’);
first require call.
3. .js is added automatically and is not
needed to at the end of module name.
4. Path Resolution: Node.js searches for
modules in core, node_modules, and file
paths.
3.6 Creating first Node Server
3.6 Creating first Node Server
3.6 Creating first Node Server

Run the code with:

node app.js
3.6 Creating first Node Server
3.6 Creating first Node Server
Revision
• Click to edit Master text styles
1. How
• SecondDNSlevel
• Third level
Works?
2. How Web Works?
• Fourth level
• Fifth level

3. What are Protocols?


4. Node Core Modules
5. Require Keyword
6. Creating first Node Server
4. Request & Response

1. Node Lifecycle & Event Loop


2. How to exit Event Loop
3. Understand Request Object
4. Sending Response
5. Routing Requests
6. Taking User Input
7. Redirecting Requests
4.1 Node Lifecycle & Event Loop
4.2 How to exit Event Loop
4.3 Understand Request Object

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
4.3 Understand Request Object

Use the browser to access:


http://localhost:3000/
http://localhost:3000/products
4.4 Sending Response
4.4 Sending Response
4.5 Routing Requests
4.5 Routing Requests
4.5 Routing Requests
4.6 Taking User Input
4.7 Redirecting Requests
Practise Set
Create a page that shows a navigation bar of
Myntra with the following links:
A. Home
B. Men
C. Women
D. Kids
E. Cart
Clicking on each link page should navigate to that
page and a welcome to section text is shown
there.
Revision
• Click to edit Master text styles
1. Node Lifecycle & Event Loop
• Second level
• Third level

2. How to exit Event Loop


• Fourth level
• Fifth level

3. Understand Request Object


4. Sending Response
5. Routing Requests
6. Taking User Input
7. Redirecting Requests
5. Parsing Request

1. Streams
2. Chunks
3. Buffers
4. Reading Chunk
5. Buffering Chunks
6. Parsing Request
7. Using Modules
5.1 Streams
5.1 Streams
5.2 Chunks
5.2 Chunks
5.3 Buffers
5.4 Reading Chunk
5.5 Buffering Chunks
5.6 Parsing Request
5.6 Parsing Request
5.7 Using Modules
5.7 Using Modules
Practise Set
Create a Calculator
1. Create a new Node.js project named “Calculator”.
2. On the home page (route “/”), show a welcome message and a
link to the calculator page.
3. On the “/calculator” page, display a form with two input fields
and a “Sum” button.
4. When the user clicks the “Sum” button, they should be taken to
the “/calculate-result” page, which shows the sum of the two
numbers.
○ Make sure the request goes to the server.
○ Create a separate module for the addition function.
○ Create another module to handle incoming requests.
○ On the “/calculate-result” page, parse the user input, use
the addition module to calculate the sum, and display the
result on a new HTML page.
Revision
• Click to edit Master text styles
1. Streams
• Second level
• Third level

2. Chunks • Fourth level


• Fifth level

3. Buffers
4. Reading Chunk
5. Buffering Chunks
6. Parsing Request
7. Using Modules
6. Event Loop
1. Event Driven
2. Single Threaded
3. V8 vs libuv
4. Node Runtime
5. Event Loop
6. Async Code
7. Blocking Code
6.1 Event Driven
6.2 Single Threaded
6.3 V8 vs libuv
V8:
1. Open-source JavaScript engine by Google.
2. Used in Chrome and Node.js.
3. Compiles JavaScript to native machine
code.
4. Ensures high-performance JavaScript
execution.

libuv:
1. Multi-platform support library for Node.js.
2. Handles asynchronous I/O operations.
3. Provides event-driven architecture.
4. Manages file system, networking, and
timers non-blockingly across platforms.
6.4 Node Runtime
6.4 Node Runtime
6.4 Node Runtime
6.4 Node Runtime
6.5 Event Loop
● timers: this phase executes callbacks
scheduled by setTimeout() and
setInterval().
● pending callbacks: executes I/O callbacks
deferred to the next loop iteration.
● idle, prepare: only used internally.
● poll: retrieve new I/O events; execute I/O
related callbacks (almost all with the exception
of close callbacks, the ones scheduled by
timers, and setImmediate()); node will
block here when appropriate.
● check: setImmediate() callbacks are
invoked here.
● close callbacks: some close callbacks, e.g.
socket.on('close', ...).
6.5 Event Loop
6.6 Async Code
6.6 Async Code
6.7 Blocking Code
6.7 Blocking Code
Run & Observe
Blocking vs Async
const fs = require('fs');

console.log('1. Start of script' );

// Synchronous (blocking) operation


console.log('2. Reading file synchronously' );
const dataSync = fs.readFileSync ('user-details.txt' , 'utf8');
console.log('3. Synchronous read complete' );

// Asynchronous (non-blocking) operation


console.log('4. Reading file asynchronously' );
fs.readFile('user-details.txt' , 'utf8', (err, dataAsync ) => {
if (err) throw err;
console.log('6. Asynchronous read complete' );
});

console.log('5. End of script' );


Run & Observe
Event Loop Sequence
console.log('1. Start of script');

// Microtask queue (Promise)


Promise.resolve().then(() => console.log('2. Microtask 1'));

// Timer queue
setTimeout(() => console.log('3. Timer 1'), 0);

// I/O queue
const fs = require('fs');
fs.readFile('user-details.txt', () => console.log('4. I/O operation'));

// Check queue
setImmediate(() => console.log('5. Immediate 1'));

// Close queue
process.on('exit', (code) => {
console.log('6. Exit event');
});

console.log('7. End of script');


Revision

1. • Click
Event to edit Master text styles
• Second levelDriven
• Third level
2. Single Threaded
• Fourth level
• Fifth level

3. V8 vs libuv
4. Node Runtime
5. Event Loop
6. Async Code
7. Blocking Code
7. NPM & Tools

1. Install Material Icons


2. npm init
3. npm Scripts
4. npm Packages
5. Installing Packages
6. Installing nodemon
7. Using nodemon
7.1 Install Material Icons
7.2 npm init
npm init
7.3 npm Scripts
npm start
npm run khul-ja-sim-sim
7.4 npm Packages

1. npm: Node.js package manager for code sharing.


2. Package: Reusable code or library.
3. package.json: Defines package metadata and
dependencies.
4. Versioning: Manages different package versions.
5. Local/Global: Install packages locally or globally.
6. Registry: Public storage for open-source packages.
7. Examples: Express, React, Lodash.
7.5 Installing Packages
npm install <package-name>

1. –save: Adds the package to the project’s dependencies in


package.json.
2. –save-dev: Adds the package to the project’s devDependencies
(used only in development) in package.json.
3. -g: Installs the package globally, making it available
system-wide, not just in a specific project.
4. –save-exact: Installs the exact version specified without
updating for newer versions.
5. –force: Forces npm to fetch and install packages even if they
are already installed.
7.6 Installing nodemon
npm install nodemon --save-dev

npm install
Recreates node_modules
7.7 Using nodemon

npm install nodemon -g


Revision
• Click to edit Master text styles
• Second level
1. Install
• Third levelMaterial Icons
• Fourth level

2. npm init • Fifth level

3. npm Scripts
4. npm Packages
5. Installing Packages
6. Installing nodemon
7. Using nodemon
8. Errors & Debugging

1. Types of Errors
2. Syntax Errors
3. Runtime Errors
4. Logical Errors
5. Using the Debugger
6. Debugger with Async Code
7. Restart Debug with nodemon
8.1 Types of Errors

1. Syntax Error: An error in the code’s structure, causing it to


not compile or run (e.g., missing semicolon).
2. Logical Error: The code runs but produces incorrect results
due to faulty logic (e.g., wrong formula).
3. Runtime Error: An error that occurs while the program is
running, often due to invalid operations
8.2 Syntax Errors
8.3 Runtime Errors
8.4 Logical Errors
8.5 Using the Debugger
Step 1 Step 3: Put a breakpoint

Step 2
8.5 Using the Debugger
Step 4: Use the tools Step 6: Debug Panel

Step 5: Hover
8.5 Using the Debugger
Step 7: Using Debug Console
8.6 Debugger with Async Code
8.7 Restart Debug with nodemon
Practise Set
Debug and fix Syntax, Runtime and Logical Errors
function calculateArea(width, height {
return width + height;
}

let width = 10 height = 5;

if (area > 100) {


console.log("The area is large.");
} else {
console.log("The area is small.");
}

if (width + height > 100) {


console.log("Area is greater than or equal to 100");
}
Revision
• Click to edit Master text styles
1. Types of Errors
• Second level
• Third level
• Fourth level

2. Syntax Errors
• Fifth level

3. Runtime Errors
4. Logical Errors
5. Using the Debugger
6. Debugger with Async Code
7. Restart Debug with nodemon

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy