SlideShare une entreprise Scribd logo
1  sur  59
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Webpage
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Agenda
❖ Client Server Architecture
❖ Limitations of Multi–Threaded Model
❖ What is Node.js?
❖ Features of Node.js
❖ Node.js Installation
❖ Blocking Vs. Non – Blocking I/O
❖ Creating Node.js First Program
❖ Node.js Modules
❖ Demo – Grocery List Web Application using Node.js
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Client – Server Architecture
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Client Server Architecture
Client 1
Client 2
Client 3
Server Database
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Traditional Multi-Threaded Model
Handle Request
A
Handle Request
B
Handle Request
C
Read ResponseRead Request
Assign Thread for A
Assign Thread for C
Assign Thread for B
Thread
Thread
Thread
User HTTP Request A
User HTTP Request B
User HTTP Request C
User HTTP Request D
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Limitations
of
Multi – Threaded Approach
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Limitations of Multi-Threaded Models
Shared
Resources
Updating
Resources
Wants to
Update
Wants to
Update
Thread A Thread C
Thread B
➢ In a multi-threaded HTTP server, for each and every request that the server receives, it creates a separate thread
which handles that request
➢ If a request acquires a lock in the shared resource and it is ‘exclusive’, it will affect result of other requests
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
High chances of deadlock if application
is not designed properly
Limitations of Multi-Threaded Models
Web Servers need to handle thousands
of HTTP requests. So, many threads may
have to wait for network operations
For thousands of simultaneous requests,
spawning threads for all processes would
not achieve the desired scalability
Scalability
Complex
Deadlock
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
What is Node.js ?
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
What is Node.js?
➢Node.js is an open source runtime environment for server-side and networking applications and is single threaded.
➢Uses Google JavaScript V8 Engine to execute code.
➢It is cross platform environment and can run on OS X, Microsoft Windows, Linux, FreeBSD, NonStop and IBM.
➢Provides an event driven architecture and non blocking I/O that is optimized and scalable.
N O D E
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Features of Node.js
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Features of Node.js
1. Asynchronous
Caller Recipient
request
response
callback
➢ When request is made to server, instead of waiting for the request to complete, server continues to
process other requests
➢ When request processing completes, the response is sent to caller using callback mechanism
Asynchronous Model
Asynchronous
Event Driven
Very Fast
Scalable
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Features of Node.js
➢ When request is made to server, instead of waiting for the request to complete, server continues to
process other requests
➢ When request processing completes, the response is sent to caller using callback mechanism
Event Emitters
Event Loop
(Single - threaded)
File System
Network
Process
Other
Event Queue
Thread Pool
2. Single Threaded and Event Driven:
Asynchronous
Event Driven
Very Fast
Scalable
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Features of Node.js
3. Very Fast
4. Single Threaded but Highly Scalable
Being built on Google Chrome's V8 JavaScript Engine, Node.js library is very fast in code
execution.
Node.js is highly scalable because event mechanism helps the server to respond in a non-
blocking way.
Asynchronous
Event Driven
Very Fast
Scalable
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Node.js Installation
EDUREKA NODE JS CERTIFICATION TRAINING www.edureka.co/mastering-node-js
Node.js Installation
Go to https://nodejs.org/en/1
Download and Install2
EDUREKA NODE JS CERTIFICATION TRAINING www.edureka.co/mastering-node-js
Node.js Installation
Open node.js command prompt3
➢ node –version
Check the version of Node.js
installed
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Creating Your First Node.js Program
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Node.js First Program
Create a Directory: mkdir node_example1
Create a File: first_example.js2
Go to the node_example directory3
Execute the java script file: node first_example.js4
2
1
3
4
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Simple Web Application Example
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Simple Web Application Example
Example:
Importing Module:
‘require’ is used to load a Node.js modules.
1
Example:
Creating Server
➢ Used to create web server object
➢ Function (request, response) is called once for
every HTTP request to the server, so it's called
the request handler.
2
listen(<port_no>)
Bind the server instance for listening to a particular port.3
Example:
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Simple Web Application Example
1 Import HTTP Module
2 Define Port No.
3 Creating Server Instance
4 Sending HTTP Header
6
Binding Server Instance
with the Port No. 3000
5 Sending Data
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Simple Web Application Example
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Blocking vs Non - Blocking
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Blocking vs Non–Blocking I/O
➢ Blocking is when the execution of additional JavaScript in the Node.js process must wait until a non-JavaScript
operation completes.
➢ "I/O" refers primarily to interaction with the system's disk and network supported by libuv.
More methods will be blocked till
the read method is not executed
More method will execute
asynchronously
(non-blocking way)
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Blocking vs Non–Blocking I/O
Non – Blocking Example:
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Blocking vs Non–Blocking I/O
Blocking Example:
C O N C L U S I O N :
➢ In case of Asynchronous (non-blocking ), once file I/O is complete, it will call the callback function
➢ This allows Node.js to be scalable and process large number of request without worrying about blocking I/O
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Node.js Modules
02
GLOBALS
03
FILE SYSTEM
04
CALLBACKS
05
EVENT
06
HTTP
01
NPM
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
NPM
➢ NPM stands for Node Package Manager
➢ Provides online repositories for node.js packages/modules
➢ Provides command line utility to install Node.js packages along with version management and dependency
management.
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
NPM
npm install Install all the modules as specified in package.json
npm install <Module Name> Install Module using npm
npm install <Module Name> -g Install dependency globally
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Basic Concepts:
02
GLOBALS
03
FILE SYSTEM
04
CALLBACKS
05
EVENT
06
HTTP
01
NPM
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Global Objects
These objects are available in all modules and therefore, are referred as Global Objects
specifies the name of the directory that currently contains the code.
__dirname
specifies the name of the file that currently contains the code.
__filename
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Global Objects
A timer in Node.js is an internal construct that calls a given function after a certain period of time.
setTimeout(callback, delay[, ...args])
➢ Schedules execution of a one-time callback after delay milliseconds
➢ Returns a Timeout for use with clearTimeout( )
setInterval(callback, delay[, ...args])
➢ Schedules repeated execution of callback every delay milliseconds.
➢ Returns a Timeout for use with clearTimeout( )
setImmediate(callback, [,..args])
➢ Schedules an immediate execution of the callback after I/O events' callbacks but
before setTimeout() and setInterval() timers are triggered.
➢ Returns an Immediate for use with clearImmediate().
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Global Objects
output
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Node.js Modules
02
GLOBALS
03
FILE SYSTEM
04
CALLBACKS
05
EVENT
06
HTTP
01
NPM
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
File System
File I/O is provided by simple wrappers around standard POSIX functions. For importing File
System Module (fs), we use: var fs = require("fs");
All methods have asynchronous and synchronous formsImportant Note:
FS Methods
Asynchronous
Forms
Synchronous
Forms
1
var fs = require("fs");
// Asynchronous read
fs.readFile(‘test.txt', function (err, data) { });
// Synchronous read
var data = fs.readFileSync('input.txt');
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
File System
The asynchronous form always takes a completion callback as its last argument.
var fs = require("fs");
// Asynchronous read
fs.readFile(‘test.txt’, function (err, data) {
if (err) {
return console.error(err);
}
console.log(data.toString());
});
FS Methods
Arg 1
Callback Method
(last argument)
Arg 2
Arg 3
Callback As Last Arg.
Important Note: 2
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
File System
First argument in completion callback is always reserved for an exceptionImportant Note: 3
Callback
Method
Arg 1: exception
Arg N
Arg 2
Arg 3
var fs = require("fs");
// Asynchronous read
fs.readFile(‘test.txt’, function (err, data) {
if (err) {
return console.error(err);
}
console.log(data.toString());
});
Reserved for
exception
returns null or undefined
(successful completion)
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Some Methods in File System Module – Open()
fs.open( path, flags[, mode], callback )
fs.openSync( path, flags[, mode] )
fs.close( fd, callback )
➢ var fs = require(‘fs’);
Open File Asynchronously
Open File Synchronously
Closing File
Arguments Description
Path < string > Path of the file
Flags < string > Access Modifiers
Mode < integer > sets the permission and sticky bits, but only if the file was created
Callback < function > Callback signature - function(err, fd)
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Flag Modes in Open Method
Modes Description
r Open file for reading. an exception occurs if the file does not exist
r+ Open file for reading and writing. Exception: if the file does not exist
w Open file for writing. The file is created ( if it does not exist) or truncated (if it exists)
wx Like 'w' but fails if path exists
w+ Open file for reading and writing. File is created (if it does not exist) or truncated (if it exists)
wx+ Same as 'w+' but fails if path exists
a Open file for appending. The file is created if it does not exist
ax Like 'a' but fails if path exists
a+ open file for reading and appending. the file is created if it does not exist.
ax+ Like 'a+' but fails if path exists
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Some Methods in File System Module – Read()
read(fd, buffer, offset, length, position, callback)
readFile(file[, options], callback)
readFileSync(file[, options])
Read Content of a File into Buffer
Reads File Asynchronously
Arguments Description
fd < integer > File Descriptor
buffer <string | Buffer | Unit8Array > The buffer that the data will be written to.
offset < integer > Offset in the buffer to start writing at.
length < integer > Specifies the number of bytes to read.
position < integer > Specifies where to begin reading from in the file
Callback < function > Read Callback signature - function(err, bytesRead, buffer)
Reads File Synchronously
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Some Methods in File System Module – Write()
writeFile(file, data[, options], callback)
writeFileSync(file, data[, options])
Writes into a File Asynchronously
Arguments Description
File Filename or File Descriptor
Data The buffer that the data will be written to.
Options: Encoding, Mode or flag
Callback < function > Callback signature - function(err, bytesRead, buffer)
Writes into a File Synchronously
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Node.js Modules
02
GLOBALS
03
FILE SYSTEM
04
CALLBACKS
05
EVENT
06
HTTP
01
NPM
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Some Methods in File System Module – Write()
Callback is an asynchronous equivalent for a function and is called at the completion of each task
Callback: will execute after
file read is complete
Output:
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Node.js Modules
02
GLOBALS
03
FILE SYSTEM
04
CALLBACKS
05
EVENT
06
HTTP
01
NPM
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Events
➢ Node.js follows event-driven architecture where certain objects (called "emitters") periodically emit
named events which further invokes the listeners (function).
➢ Node.js provide concurrency by using the concept of events and callbacks
➢ All objects that emit events are instances of the EventEmitter class.
var eventEmitter = event.EventEmitter();
Importing ‘events’ module
Object of EventEmitter Class
eventEmitter.emit(‘event’)
Registering listeners
Trigger event
eventEmitter.on(‘event’, eventHandler)
var event = require(‘events’);
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Events
Import Events Module
Creating object of EventEmitter
Emitting event
Registering Listener and defining
event handler
OUTPUT
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Node.js Modules
02
GLOBALS
03
FILE SYSTEM
04
CALLBACKS
05
EVENT
06
HTTP
01
NPM
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Web Application Architecture
Client Client Client Client
Mobile
Browser
Web
Browser
Application
Web Server
Application
Server
File System
Database
External
File System
Client Server Business Layer Data Layer
Makes HTTP Request
to the server
Serve the request
Made by client and
pass the response
contains application
utilized by web server to
do required processing.
Consists of Database
and other data storage
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
HTTP
Import Required Modules
Creating Server
Parse the fetched URL to get pathname
Request file to be read from file system
(index.html)
Creating Header with content type as text or HTML
Generating Response
Listening to port: 3000
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
HTTP
Index.html
Output
Node.js cmd
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Express
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Express Framework
➢ Express is a minimal and flexible Node.js web application framework that provides a robust set of features for
web and mobile applications.
➢ Inspired by Sinatra (web framework based on Ruby) and also, intertwined with Connect, a “plugin” library for
Node.
➢ Express used to come bundled with Connect before version 4.0
➢ After version 4.0, Connect (and all middleware except static) was removed to allow these middleware to be
updated independently
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Express Framework
Importing express module
Retrieve resources
Sending html doc as response
Listening to port: 3000
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
RESTful API
REST stands for REpresentational State Transfer.
Used create a new resource
or update a existing
resource
1 POST
Used to provide a read
only access to a resource
2 GET
Used to create a update
a resource
3 PUT
Used to remove a resource
4 DELETE
C R U DCreate Delete
Read Update
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Popular Frameworks Around
Node.js
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Popular Frameworks Around Node.js
E X P R E S S
Minimalistic Web
Framework based on
Node.js
S A I L S
Project generator,
Middleware and
Templating Engine
M E T E O R
Full Stack Framework
that covers server,
mobile, desktop & web
apps
K O A
Web Framework
designed by the team
behind Express
N O D E
www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING
Demo:
Grocery List Web Application
EDUREKA NODE JS CERTIFICATION TRAINING www.edureka.co/mastering-node-js
Thank You …
Questions/Queries/Feedback

Contenu connexe

Tendances

Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Adieu
 

Tendances (20)

NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
React workshop
React workshopReact workshop
React workshop
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Angular
AngularAngular
Angular
 
React js
React jsReact js
React js
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Introduction to NodeJS
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJS
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Intro to vue.js
Intro to vue.jsIntro to vue.js
Intro to vue.js
 
Vue.js for beginners
Vue.js for beginnersVue.js for beginners
Vue.js for beginners
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Express js
Express jsExpress js
Express js
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Nodejs functions & modules
Nodejs functions & modulesNodejs functions & modules
Nodejs functions & modules
 
Basics of Vue.js 2019
Basics of Vue.js 2019Basics of Vue.js 2019
Basics of Vue.js 2019
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 

Similaire à Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js Training | Edureka

Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps Approach
Akshaya Mahapatra
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
MS Cloud Day - Deploying and monitoring windows azure applications
MS Cloud Day - Deploying and monitoring windows azure applicationsMS Cloud Day - Deploying and monitoring windows azure applications
MS Cloud Day - Deploying and monitoring windows azure applications
Spiffy
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
Edureka!
 
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
Tom Croucher
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 

Similaire à Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js Training | Edureka (20)

Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps Approach
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
OSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
 
MS Cloud Day - Deploying and monitoring windows azure applications
MS Cloud Day - Deploying and monitoring windows azure applicationsMS Cloud Day - Deploying and monitoring windows azure applications
MS Cloud Day - Deploying and monitoring windows azure applications
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
 
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
 
Resilience Testing
Resilience Testing Resilience Testing
Resilience Testing
 
Deep Dive OpenShitt on Azure & .NET Core on OpenShift
Deep Dive OpenShitt on Azure & .NET Core on OpenShiftDeep Dive OpenShitt on Azure & .NET Core on OpenShift
Deep Dive OpenShitt on Azure & .NET Core on OpenShift
 
Spring Cloud: API gateway upgrade & configuration in the cloud
Spring Cloud: API gateway upgrade & configuration in the cloudSpring Cloud: API gateway upgrade & configuration in the cloud
Spring Cloud: API gateway upgrade & configuration in the cloud
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6
 
Introduction to Node JS.pdf
Introduction to Node JS.pdfIntroduction to Node JS.pdf
Introduction to Node JS.pdf
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
 
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
 

Plus de Edureka!

Plus de Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js Training | Edureka

  • 1. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Webpage
  • 2. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Agenda ❖ Client Server Architecture ❖ Limitations of Multi–Threaded Model ❖ What is Node.js? ❖ Features of Node.js ❖ Node.js Installation ❖ Blocking Vs. Non – Blocking I/O ❖ Creating Node.js First Program ❖ Node.js Modules ❖ Demo – Grocery List Web Application using Node.js
  • 3. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Client – Server Architecture
  • 4. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Client Server Architecture Client 1 Client 2 Client 3 Server Database
  • 5. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Traditional Multi-Threaded Model Handle Request A Handle Request B Handle Request C Read ResponseRead Request Assign Thread for A Assign Thread for C Assign Thread for B Thread Thread Thread User HTTP Request A User HTTP Request B User HTTP Request C User HTTP Request D
  • 6. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Limitations of Multi – Threaded Approach
  • 7. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Limitations of Multi-Threaded Models Shared Resources Updating Resources Wants to Update Wants to Update Thread A Thread C Thread B ➢ In a multi-threaded HTTP server, for each and every request that the server receives, it creates a separate thread which handles that request ➢ If a request acquires a lock in the shared resource and it is ‘exclusive’, it will affect result of other requests
  • 8. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING High chances of deadlock if application is not designed properly Limitations of Multi-Threaded Models Web Servers need to handle thousands of HTTP requests. So, many threads may have to wait for network operations For thousands of simultaneous requests, spawning threads for all processes would not achieve the desired scalability Scalability Complex Deadlock
  • 9. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING What is Node.js ?
  • 10. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING What is Node.js? ➢Node.js is an open source runtime environment for server-side and networking applications and is single threaded. ➢Uses Google JavaScript V8 Engine to execute code. ➢It is cross platform environment and can run on OS X, Microsoft Windows, Linux, FreeBSD, NonStop and IBM. ➢Provides an event driven architecture and non blocking I/O that is optimized and scalable. N O D E
  • 11. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Features of Node.js
  • 12. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Features of Node.js 1. Asynchronous Caller Recipient request response callback ➢ When request is made to server, instead of waiting for the request to complete, server continues to process other requests ➢ When request processing completes, the response is sent to caller using callback mechanism Asynchronous Model Asynchronous Event Driven Very Fast Scalable
  • 13. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Features of Node.js ➢ When request is made to server, instead of waiting for the request to complete, server continues to process other requests ➢ When request processing completes, the response is sent to caller using callback mechanism Event Emitters Event Loop (Single - threaded) File System Network Process Other Event Queue Thread Pool 2. Single Threaded and Event Driven: Asynchronous Event Driven Very Fast Scalable
  • 14. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Features of Node.js 3. Very Fast 4. Single Threaded but Highly Scalable Being built on Google Chrome's V8 JavaScript Engine, Node.js library is very fast in code execution. Node.js is highly scalable because event mechanism helps the server to respond in a non- blocking way. Asynchronous Event Driven Very Fast Scalable
  • 15. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Node.js Installation
  • 16. EDUREKA NODE JS CERTIFICATION TRAINING www.edureka.co/mastering-node-js Node.js Installation Go to https://nodejs.org/en/1 Download and Install2
  • 17. EDUREKA NODE JS CERTIFICATION TRAINING www.edureka.co/mastering-node-js Node.js Installation Open node.js command prompt3 ➢ node –version Check the version of Node.js installed
  • 18. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Creating Your First Node.js Program
  • 19. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Node.js First Program Create a Directory: mkdir node_example1 Create a File: first_example.js2 Go to the node_example directory3 Execute the java script file: node first_example.js4 2 1 3 4
  • 20. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Simple Web Application Example
  • 21. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Simple Web Application Example Example: Importing Module: ‘require’ is used to load a Node.js modules. 1 Example: Creating Server ➢ Used to create web server object ➢ Function (request, response) is called once for every HTTP request to the server, so it's called the request handler. 2 listen(<port_no>) Bind the server instance for listening to a particular port.3 Example:
  • 22. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Simple Web Application Example 1 Import HTTP Module 2 Define Port No. 3 Creating Server Instance 4 Sending HTTP Header 6 Binding Server Instance with the Port No. 3000 5 Sending Data
  • 23. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Simple Web Application Example
  • 24. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Blocking vs Non - Blocking
  • 25. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Blocking vs Non–Blocking I/O ➢ Blocking is when the execution of additional JavaScript in the Node.js process must wait until a non-JavaScript operation completes. ➢ "I/O" refers primarily to interaction with the system's disk and network supported by libuv. More methods will be blocked till the read method is not executed More method will execute asynchronously (non-blocking way)
  • 26. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Blocking vs Non–Blocking I/O Non – Blocking Example:
  • 27. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Blocking vs Non–Blocking I/O Blocking Example: C O N C L U S I O N : ➢ In case of Asynchronous (non-blocking ), once file I/O is complete, it will call the callback function ➢ This allows Node.js to be scalable and process large number of request without worrying about blocking I/O
  • 28. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Node.js Modules 02 GLOBALS 03 FILE SYSTEM 04 CALLBACKS 05 EVENT 06 HTTP 01 NPM
  • 29. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING NPM ➢ NPM stands for Node Package Manager ➢ Provides online repositories for node.js packages/modules ➢ Provides command line utility to install Node.js packages along with version management and dependency management.
  • 30. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING NPM npm install Install all the modules as specified in package.json npm install <Module Name> Install Module using npm npm install <Module Name> -g Install dependency globally
  • 31. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Basic Concepts: 02 GLOBALS 03 FILE SYSTEM 04 CALLBACKS 05 EVENT 06 HTTP 01 NPM
  • 32. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Global Objects These objects are available in all modules and therefore, are referred as Global Objects specifies the name of the directory that currently contains the code. __dirname specifies the name of the file that currently contains the code. __filename
  • 33. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Global Objects A timer in Node.js is an internal construct that calls a given function after a certain period of time. setTimeout(callback, delay[, ...args]) ➢ Schedules execution of a one-time callback after delay milliseconds ➢ Returns a Timeout for use with clearTimeout( ) setInterval(callback, delay[, ...args]) ➢ Schedules repeated execution of callback every delay milliseconds. ➢ Returns a Timeout for use with clearTimeout( ) setImmediate(callback, [,..args]) ➢ Schedules an immediate execution of the callback after I/O events' callbacks but before setTimeout() and setInterval() timers are triggered. ➢ Returns an Immediate for use with clearImmediate().
  • 34. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Global Objects output
  • 35. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Node.js Modules 02 GLOBALS 03 FILE SYSTEM 04 CALLBACKS 05 EVENT 06 HTTP 01 NPM
  • 36. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING File System File I/O is provided by simple wrappers around standard POSIX functions. For importing File System Module (fs), we use: var fs = require("fs"); All methods have asynchronous and synchronous formsImportant Note: FS Methods Asynchronous Forms Synchronous Forms 1 var fs = require("fs"); // Asynchronous read fs.readFile(‘test.txt', function (err, data) { }); // Synchronous read var data = fs.readFileSync('input.txt');
  • 37. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING File System The asynchronous form always takes a completion callback as its last argument. var fs = require("fs"); // Asynchronous read fs.readFile(‘test.txt’, function (err, data) { if (err) { return console.error(err); } console.log(data.toString()); }); FS Methods Arg 1 Callback Method (last argument) Arg 2 Arg 3 Callback As Last Arg. Important Note: 2
  • 38. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING File System First argument in completion callback is always reserved for an exceptionImportant Note: 3 Callback Method Arg 1: exception Arg N Arg 2 Arg 3 var fs = require("fs"); // Asynchronous read fs.readFile(‘test.txt’, function (err, data) { if (err) { return console.error(err); } console.log(data.toString()); }); Reserved for exception returns null or undefined (successful completion)
  • 39. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Some Methods in File System Module – Open() fs.open( path, flags[, mode], callback ) fs.openSync( path, flags[, mode] ) fs.close( fd, callback ) ➢ var fs = require(‘fs’); Open File Asynchronously Open File Synchronously Closing File Arguments Description Path < string > Path of the file Flags < string > Access Modifiers Mode < integer > sets the permission and sticky bits, but only if the file was created Callback < function > Callback signature - function(err, fd)
  • 40. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Flag Modes in Open Method Modes Description r Open file for reading. an exception occurs if the file does not exist r+ Open file for reading and writing. Exception: if the file does not exist w Open file for writing. The file is created ( if it does not exist) or truncated (if it exists) wx Like 'w' but fails if path exists w+ Open file for reading and writing. File is created (if it does not exist) or truncated (if it exists) wx+ Same as 'w+' but fails if path exists a Open file for appending. The file is created if it does not exist ax Like 'a' but fails if path exists a+ open file for reading and appending. the file is created if it does not exist. ax+ Like 'a+' but fails if path exists
  • 41. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Some Methods in File System Module – Read() read(fd, buffer, offset, length, position, callback) readFile(file[, options], callback) readFileSync(file[, options]) Read Content of a File into Buffer Reads File Asynchronously Arguments Description fd < integer > File Descriptor buffer <string | Buffer | Unit8Array > The buffer that the data will be written to. offset < integer > Offset in the buffer to start writing at. length < integer > Specifies the number of bytes to read. position < integer > Specifies where to begin reading from in the file Callback < function > Read Callback signature - function(err, bytesRead, buffer) Reads File Synchronously
  • 42. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Some Methods in File System Module – Write() writeFile(file, data[, options], callback) writeFileSync(file, data[, options]) Writes into a File Asynchronously Arguments Description File Filename or File Descriptor Data The buffer that the data will be written to. Options: Encoding, Mode or flag Callback < function > Callback signature - function(err, bytesRead, buffer) Writes into a File Synchronously
  • 43. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Node.js Modules 02 GLOBALS 03 FILE SYSTEM 04 CALLBACKS 05 EVENT 06 HTTP 01 NPM
  • 44. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Some Methods in File System Module – Write() Callback is an asynchronous equivalent for a function and is called at the completion of each task Callback: will execute after file read is complete Output:
  • 45. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Node.js Modules 02 GLOBALS 03 FILE SYSTEM 04 CALLBACKS 05 EVENT 06 HTTP 01 NPM
  • 46. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Events ➢ Node.js follows event-driven architecture where certain objects (called "emitters") periodically emit named events which further invokes the listeners (function). ➢ Node.js provide concurrency by using the concept of events and callbacks ➢ All objects that emit events are instances of the EventEmitter class. var eventEmitter = event.EventEmitter(); Importing ‘events’ module Object of EventEmitter Class eventEmitter.emit(‘event’) Registering listeners Trigger event eventEmitter.on(‘event’, eventHandler) var event = require(‘events’);
  • 47. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Events Import Events Module Creating object of EventEmitter Emitting event Registering Listener and defining event handler OUTPUT
  • 48. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Node.js Modules 02 GLOBALS 03 FILE SYSTEM 04 CALLBACKS 05 EVENT 06 HTTP 01 NPM
  • 49. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Web Application Architecture Client Client Client Client Mobile Browser Web Browser Application Web Server Application Server File System Database External File System Client Server Business Layer Data Layer Makes HTTP Request to the server Serve the request Made by client and pass the response contains application utilized by web server to do required processing. Consists of Database and other data storage
  • 50. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING HTTP Import Required Modules Creating Server Parse the fetched URL to get pathname Request file to be read from file system (index.html) Creating Header with content type as text or HTML Generating Response Listening to port: 3000
  • 51. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING HTTP Index.html Output Node.js cmd
  • 52. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Express
  • 53. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Express Framework ➢ Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. ➢ Inspired by Sinatra (web framework based on Ruby) and also, intertwined with Connect, a “plugin” library for Node. ➢ Express used to come bundled with Connect before version 4.0 ➢ After version 4.0, Connect (and all middleware except static) was removed to allow these middleware to be updated independently
  • 54. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Express Framework Importing express module Retrieve resources Sending html doc as response Listening to port: 3000
  • 55. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING RESTful API REST stands for REpresentational State Transfer. Used create a new resource or update a existing resource 1 POST Used to provide a read only access to a resource 2 GET Used to create a update a resource 3 PUT Used to remove a resource 4 DELETE C R U DCreate Delete Read Update
  • 56. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Popular Frameworks Around Node.js
  • 57. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Popular Frameworks Around Node.js E X P R E S S Minimalistic Web Framework based on Node.js S A I L S Project generator, Middleware and Templating Engine M E T E O R Full Stack Framework that covers server, mobile, desktop & web apps K O A Web Framework designed by the team behind Express N O D E
  • 58. www.edureka.co/mastering-node-jsEDUREKA NODE JS CERTIFICATION TRAINING Demo: Grocery List Web Application
  • 59. EDUREKA NODE JS CERTIFICATION TRAINING www.edureka.co/mastering-node-js Thank You … Questions/Queries/Feedback