SlideShare a Scribd company logo
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

PPTX
Nodejs functions & modules
PPTX
java script
KEY
Building a real life application in node js
PDF
Introduction to nodejs
PDF
How to build to do app using vue composition api and vuex 4 with typescript
PPTX
Overview of Node JS
PDF
Express node js
PDF
Introduction to Node.js Platform
Nodejs functions & modules
java script
Building a real life application in node js
Introduction to nodejs
How to build to do app using vue composition api and vuex 4 with typescript
Overview of Node JS
Express node js
Introduction to Node.js Platform

What's hot (20)

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

Similar to Intsllation & 1st program nodejs (20)

PPTX
Node.js web-based Example :Run a local server in order to start using node.js...
PDF
5.node js
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
PPT
nodejs_at_a_glance.ppt
PPT
nodejs_at_a_glance, understanding java script
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
PDF
Introduction to Node.js
PPTX
Intro to Node
KEY
Writing robust Node.js applications
PPTX
Introduction to Node.js
KEY
Node.js
PDF
Introduction to Node.js
PPTX
Node.js: The What, The How and The When
PPTX
Introduction to node.js
PDF
Node.js introduction
PDF
Introduction to Node js for beginners + game project
PPTX
Node.js System: The Approach
PPT
nodejs tutorial foor free download from academia
ODP
Introduce about Nodejs - duyetdev.com
PPTX
Local SQLite Database with Node for beginners
Node.js web-based Example :Run a local server in order to start using node.js...
5.node js
A language for the Internet: Why JavaScript and Node.js is right for Internet...
nodejs_at_a_glance.ppt
nodejs_at_a_glance, understanding java script
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Introduction to Node.js
Intro to Node
Writing robust Node.js applications
Introduction to Node.js
Node.js
Introduction to Node.js
Node.js: The What, The How and The When
Introduction to node.js
Node.js introduction
Introduction to Node js for beginners + game project
Node.js System: The Approach
nodejs tutorial foor free download from academia
Introduce about Nodejs - duyetdev.com
Local SQLite Database with Node for beginners
Ad

More from monikadeshmane (19)

PPTX
File system node js
PPTX
Nodejs buffers
PPTX
Nodejs basics
PPTX
Chap 5 php files part-2
PPTX
Chap 5 php files part 1
PPTX
Chap4 oop class (php) part 2
PPTX
Chap4 oop class (php) part 1
PPTX
Chap 3php array part4
PPTX
Chap 3php array part 3
PPTX
Chap 3php array part 2
PPTX
Chap 3php array part1
PPTX
PHP function
PPTX
php string part 4
PPTX
php string part 3
PPTX
php string-part 2
PPTX
PHP string-part 1
PPT
ip1clientserver model
PPTX
Chap1introppt2php(finally done)
PPTX
Chap1introppt1php basic
File system node js
Nodejs buffers
Nodejs basics
Chap 5 php files part-2
Chap 5 php files part 1
Chap4 oop class (php) part 2
Chap4 oop class (php) part 1
Chap 3php array part4
Chap 3php array part 3
Chap 3php array part 2
Chap 3php array part1
PHP function
php string part 4
php string part 3
php string-part 2
PHP string-part 1
ip1clientserver model
Chap1introppt2php(finally done)
Chap1introppt1php basic

Recently uploaded (20)

PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Cell Structure & Organelles in detailed.
PDF
From loneliness to social connection charting
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
The Final Stretch: How to Release a Game and Not Die in the Process.
Cardiovascular Pharmacology for pharmacy students.pptx
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
O7-L3 Supply Chain Operations - ICLT Program
human mycosis Human fungal infections are called human mycosis..pptx
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Module 3: Health Systems Tutorial Slides S2 2025
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Cell Structure & Organelles in detailed.
From loneliness to social connection charting
Pharmacology of Heart Failure /Pharmacotherapy of CHF

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?