SlideShare a Scribd company logo
1 of 17
INTRODUCTION
TO NODE JS
1
Monica Deshmane(H.V.Desai College, Pune)
What we Learn?
points
Monica Deshmane(H.V.Desai College, Pune)
Note-before this refer node JS basics.ppt
Installation of Node JS
1st program of Node JS
Node JS event loop
Installation of Node JS
1. Download Node.js
The official Node.js website has installation instructions
for Node.js: https://nodejs.org
2. download visual studio code for node js
3. U can show output on console-
Prog.1
.editor // Entering editor mode (^D to finish, ^C to cancel)
function welcome(name)
{ return `Hello ${name}!`; }
welcome('Node.js User');
// ^D
'Hello Node.js User!'
Setup
Monica Deshmane(H.V.Desai College, Pune)
Installation of Node JS
Note:- Once you have downloaded and installed Node.js on
your computer, let's try to display "Hello World" using web browser.
Create a Node.js file named "myfirst.js", and add the following code:
Prog2.
const http = require('http');
const server = http.createServer((req, res) =>
{ res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(3000);
});
Setup
Monica Deshmane(H.V.Desai College, Pune)
Creating Node.js Application
Node.js application
/* Hello, World! program in node.js */
console.log("Hello, World!")
A Node.js application consists of the following three important
components −
Node.js
application
Monica Deshmane(H.V.Desai College, Pune)
•Step 1 - Import Required Module
We use the require directive to load the http module
and store the returned HTTP instance into an http
variable
as follows −var http = require("http");
•Step 2 - Create Server
1. We use the created http instance and call http.createServer()
method to create a server instance.
2. then we bind it at port 8081 using the listen method
associated with the server instance.
3. Pass it a function with parameters request and response.
•Write the sample implementation to always return
• "Hello World".
Step1
Creating Node.js Application
•http.createServer(function (request, response)
• {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello Worldn');
}).listen(8081);
// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');
Step2
Creating Node.js Application
•Step 3 - Testing Request & Response
•Now execute the main.js to start the server as follows −
$ node main.js
Verify the Output. Server has started.
Server running at http://localhost:8081/
Step3
Monica Deshmane(H.V.Desai College, Pune
Node JS event loop
•Node.js uses events heavily and it is also one of the
reasons why Node.js is fast compared to other similar
technologies.
•In an event-driven application, there is generally a main
loop that listens for events, and then triggers a callback
function when one of those events is detected
main loop
that listens
for events
Node JS event loop
•Only 1 thread is not running in thread process to achieve
parallalism.
•Node executes instructions one by one until no further
instructions to execute.
•See this loop never terminate.
var stop=false.
setTimeout(function()
{
Stop=true;
},1000);
Monica Deshmane(H.V.Desai College, Pune)
continue...
Node JS event loop continue…
..
•In node and browser Lot of code depends on events
Window.addEventListener(‘load’,function()
{
Alert(“window loaded”);
});
DOM API deals with events by
addEventListener(),removeEventListener() & dispatchEvent().
•It uses XMLHttpRequest object in ajax.
EventListener
Monica Deshmane(H.V.Desai College, Pune)
Node JS event loop
..
• this is case of example post request
when user submit form you normally listen on data
and end event request.
•http.Server(function (req,res)
{
var buf=” ”;
req.on(“data”,function(data)
{
buf+=data;
});
req.on(“end”,function(){
console.log(“all data is ready”);
});
});
Monica Deshmane(H.V.Desai College, Pune)
continue…
Node JS event loop
..
•U can also do like
•const http = require('http');
•const server =http.createServer((req, res) =>{
•var buf='hiiiii';
•req.on('end',console.log('all data is ready‘ + buf));
•}).listen(8081);
•console.log('Server running at http://localhost:8081/');
Monica Deshmane(H.V.Desai College, Pune)
continue…
What we Learned?
points
Monica Deshmane(H.V.Desai College, Pune)
2.1 Introduction
2.2 What is Node ?
2.3 Traditional Web Server Model
2.4 Node JS Process model
2.5 Installation of Node JS
2.6 Node JS event loop
Questions..
1. What is node?why it is used?
2. What can node js do?
3. Expain traditional web server model with diagram.
4. Expain node js server model with diagram.
5. What is difference between node server & tradional server model
?explain any 4 points of differenciation.
6. Write program to display heloo msg on server using node js.
7. What are features of node js?explain each in brief.
8. What are advantages of node js?
9. What are dis-advantages of node js?
1mark questions-
What is libuv?
What is callback?
What is event loop?
Which is The official Node.js website?
What is require?
How to execute js in node js?
17
Monica Deshmane(H.V.Desai College, Pune)
End Of Chapter
Any Questions?

More Related Content

What's hot

What's hot (20)

An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
 
Express js
Express jsExpress js
Express js
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
Wt unit 4
Wt unit 4Wt unit 4
Wt unit 4
 
Communication in Node.js
Communication in Node.jsCommunication in Node.js
Communication in Node.js
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
 
REST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourREST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A Tour
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js Platform
 
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
 
Activator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupActivator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetup
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
 
Expressjs
ExpressjsExpressjs
Expressjs
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Creating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JSCreating Single Page Web App using Backbone JS
Creating Single Page Web App using Backbone JS
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
 
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
 

Similar to Intsllation & 1st program nodejs

A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
WalaSidhom1
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Richard Lee
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 

Similar to Intsllation & 1st program nodejs (20)

5.node js
5.node js5.node js
5.node js
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node.js
Node.jsNode.js
Node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The When
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introduction
 
Introduction to Node js for beginners + game project
Introduction to Node js for beginners + game projectIntroduction to Node js for beginners + game project
Introduction to Node js for beginners + game project
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginners
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
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
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
 

More from monikadeshmane

More from monikadeshmane (19)

File system node js
File system node jsFile system node js
File system node js
 
Nodejs buffers
Nodejs buffersNodejs buffers
Nodejs buffers
 
Nodejs basics
Nodejs basicsNodejs basics
Nodejs basics
 
Chap 5 php files part-2
Chap 5 php files   part-2Chap 5 php files   part-2
Chap 5 php files part-2
 
Chap 5 php files part 1
Chap 5 php files part 1Chap 5 php files part 1
Chap 5 php files part 1
 
Chap4 oop class (php) part 2
Chap4 oop class (php) part 2Chap4 oop class (php) part 2
Chap4 oop class (php) part 2
 
Chap4 oop class (php) part 1
Chap4 oop class (php) part 1Chap4 oop class (php) part 1
Chap4 oop class (php) part 1
 
Chap 3php array part4
Chap 3php array part4Chap 3php array part4
Chap 3php array part4
 
Chap 3php array part 3
Chap 3php array part 3Chap 3php array part 3
Chap 3php array part 3
 
Chap 3php array part 2
Chap 3php array part 2Chap 3php array part 2
Chap 3php array part 2
 
Chap 3php array part1
Chap 3php array part1Chap 3php array part1
Chap 3php array part1
 
PHP function
PHP functionPHP function
PHP function
 
php string part 4
php string part 4php string part 4
php string part 4
 
php string part 3
php string part 3php string part 3
php string part 3
 
php string-part 2
php string-part 2php string-part 2
php string-part 2
 
PHP string-part 1
PHP string-part 1PHP string-part 1
PHP string-part 1
 
ip1clientserver model
 ip1clientserver model ip1clientserver model
ip1clientserver model
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)
 
Chap1introppt1php basic
Chap1introppt1php basicChap1introppt1php basic
Chap1introppt1php basic
 

Recently uploaded

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 

Intsllation & 1st program nodejs

  • 1. INTRODUCTION TO NODE JS 1 Monica Deshmane(H.V.Desai College, Pune)
  • 2. What we Learn? points Monica Deshmane(H.V.Desai College, Pune) Note-before this refer node JS basics.ppt Installation of Node JS 1st program of Node JS Node JS event loop
  • 3. Installation of Node JS 1. Download Node.js The official Node.js website has installation instructions for Node.js: https://nodejs.org 2. download visual studio code for node js 3. U can show output on console- Prog.1 .editor // Entering editor mode (^D to finish, ^C to cancel) function welcome(name) { return `Hello ${name}!`; } welcome('Node.js User'); // ^D 'Hello Node.js User!' Setup Monica Deshmane(H.V.Desai College, Pune)
  • 4. Installation of Node JS Note:- Once you have downloaded and installed Node.js on your computer, let's try to display "Hello World" using web browser. Create a Node.js file named "myfirst.js", and add the following code: Prog2. const http = require('http'); const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World'); }); server.listen(3000); }); Setup Monica Deshmane(H.V.Desai College, Pune)
  • 5. Creating Node.js Application Node.js application /* Hello, World! program in node.js */ console.log("Hello, World!") A Node.js application consists of the following three important components − Node.js application Monica Deshmane(H.V.Desai College, Pune)
  • 6. •Step 1 - Import Required Module We use the require directive to load the http module and store the returned HTTP instance into an http variable as follows −var http = require("http"); •Step 2 - Create Server 1. We use the created http instance and call http.createServer() method to create a server instance. 2. then we bind it at port 8081 using the listen method associated with the server instance. 3. Pass it a function with parameters request and response. •Write the sample implementation to always return • "Hello World". Step1
  • 7. Creating Node.js Application •http.createServer(function (request, response) • { // Send the HTTP header // HTTP Status: 200 : OK // Content Type: text/plain response.writeHead(200, {'Content-Type': 'text/plain'}); // Send the response body as "Hello World" response.end('Hello Worldn'); }).listen(8081); // Console will print the message console.log('Server running at http://127.0.0.1:8081/'); Step2
  • 8. Creating Node.js Application •Step 3 - Testing Request & Response •Now execute the main.js to start the server as follows − $ node main.js Verify the Output. Server has started. Server running at http://localhost:8081/ Step3 Monica Deshmane(H.V.Desai College, Pune
  • 9. Node JS event loop •Node.js uses events heavily and it is also one of the reasons why Node.js is fast compared to other similar technologies. •In an event-driven application, there is generally a main loop that listens for events, and then triggers a callback function when one of those events is detected main loop that listens for events
  • 10. Node JS event loop •Only 1 thread is not running in thread process to achieve parallalism. •Node executes instructions one by one until no further instructions to execute. •See this loop never terminate. var stop=false. setTimeout(function() { Stop=true; },1000); Monica Deshmane(H.V.Desai College, Pune) continue...
  • 11. Node JS event loop continue… .. •In node and browser Lot of code depends on events Window.addEventListener(‘load’,function() { Alert(“window loaded”); }); DOM API deals with events by addEventListener(),removeEventListener() & dispatchEvent(). •It uses XMLHttpRequest object in ajax. EventListener Monica Deshmane(H.V.Desai College, Pune)
  • 12. Node JS event loop .. • this is case of example post request when user submit form you normally listen on data and end event request. •http.Server(function (req,res) { var buf=” ”; req.on(“data”,function(data) { buf+=data; }); req.on(“end”,function(){ console.log(“all data is ready”); }); }); Monica Deshmane(H.V.Desai College, Pune) continue…
  • 13. Node JS event loop .. •U can also do like •const http = require('http'); •const server =http.createServer((req, res) =>{ •var buf='hiiiii'; •req.on('end',console.log('all data is ready‘ + buf)); •}).listen(8081); •console.log('Server running at http://localhost:8081/'); Monica Deshmane(H.V.Desai College, Pune) continue…
  • 14. What we Learned? points Monica Deshmane(H.V.Desai College, Pune) 2.1 Introduction 2.2 What is Node ? 2.3 Traditional Web Server Model 2.4 Node JS Process model 2.5 Installation of Node JS 2.6 Node JS event loop
  • 15. Questions.. 1. What is node?why it is used? 2. What can node js do? 3. Expain traditional web server model with diagram. 4. Expain node js server model with diagram. 5. What is difference between node server & tradional server model ?explain any 4 points of differenciation. 6. Write program to display heloo msg on server using node js. 7. What are features of node js?explain each in brief. 8. What are advantages of node js? 9. What are dis-advantages of node js?
  • 16. 1mark questions- What is libuv? What is callback? What is event loop? Which is The official Node.js website? What is require? How to execute js in node js?
  • 17. 17 Monica Deshmane(H.V.Desai College, Pune) End Of Chapter Any Questions?