SlideShare a Scribd company logo
Prepared By:
Prof. Bareen Shaikh
Department of Computer
Science,
MIT ACSC, ALNDI(D), PUNE
The following tools/SDK are required for
developing a Node.js application on any
platform.
 Node.js
 Node Package Manager (NPM)
 IDE (Integrated Development Environment) or
TextEditor
Note: NPM (Node Package Manager) is included in Node.js
installation
Introduction to Node JS1.pdf
Introduction to Node JS1.pdf
Introduction to Node JS1.pdf
Introduction to Node JS1.pdf
Introduction to Node JS1.pdf
Introduction to Node JS1.pdf
Introduction to Node JS1.pdf
Introduction to Node JS1.pdf
Introduction to Node JS1.pdf
Introduction to Node JS1.pdf
 Node.js files contain tasks that will be
executed on certain events
 A typical event is someone trying to access a
port on the server
 Node.js files must be initiated on the server
before having any effect
 Node.js files have extension ".js"
A Node.js application consists of the following
three important components −
 Import required modules − Use
the require directive to load Node.js modules.
 Create server − A server which will listen to
client's requests similar to Apache HTTP Server.
 Read request and return response − The server
created in an earlier step will read the HTTP
request made by the client which can be a
browser or a console and return the response.
 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
Use the created http instance and
call http.createServer() method to create a
server instance
http.createServer(function (request,
response) {
response.writeHead(200, {'Content-Type':
'text/HTML});
response.end('Hello Worldn');
}).listen(8080);
console.log('Server running…”);
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-
Type': 'text/html'});
res.end('Hello World!');
}).listen(8080);
Note:- create a filename.js file and type above program of “Hello World”
Save file at c:usersfoldername
 Open command prompt
C:usersfoldernamenode filename.js
Server running…
 Now here your computer works as a server
 Open browser in address bar type
https://localhost:8080
 Callback is an asynchronous equivalent for a function
 A callback function is called at the completion of a
given task
 All the APIs of Node are written in such a way that
they support callbacks.
For example
A function to read a file may start reading file and
return the control to the execution environment
immediately so that the next instruction can be
executed. Once file I/O is complete, it will call the
callback function while passing the callback function,
the content of the file as a parameter. So there is no
blocking or wait for File I/O.
 This makes Node.js highly scalable, as it can process
a high number of requests without waiting for any
function to return results.
 Create a input file filename.txt
 Write some content in it
 Create .js file
 Write following code in it
var fp = require(‘fs');
var data = fp.readFileSync(‘filename.txt');
console.log(data.toString());
console.log("Program Ended");
 Run the above node in command prompt.
 Create a input file filename.txt
 Write some content in it
 Create .js file
 Write following code in it
var fp = require(‘fp');
fp.readFile(‘filename.txt', function (err, data) {
if (err) return console.error(err);
console.log(data.toString()); });
console.log("Program Ended");
 Run the above node in command prompt.
 Program ended
Blocking Non Blocking
 program blocks reads
the file and then only
it proceeds to end the
program.
 blocking program
executes very much
in sequence.
 program does not wait
for file reading and
proceeds to print
"Program Ended" and at
the same time, the
program without
blocking continues
reading the file.
 non-blocking programs
do not execute in
sequence
Introduction to Node JS1.pdf

More Related Content

PDF
FITC - Node.js 101
PDF
Basic Understanding and Implement of Node.js
PPTX
Nodejs intro
PDF
Node.js 101 with Rami Sayar
PPTX
DOCX
Node js getting started
PPTX
Node.js Workshop - Sela SDP 2015
PPTX
What is Node.js
FITC - Node.js 101
Basic Understanding and Implement of Node.js
Nodejs intro
Node.js 101 with Rami Sayar
Node js getting started
Node.js Workshop - Sela SDP 2015
What is Node.js

Similar to Introduction to Node JS1.pdf (20)

KEY
Node.js - A practical introduction (v2)
PDF
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
PPTX
PPTX
Introduction to node.js By Ahmed Assaf
PPTX
Scalable network applications, event-driven - Node JS
PPTX
Introduction to Node.js
PPTX
Starting with Node.js
PPTX
Introduction to node.js
PPTX
Introduction to Node (15th May 2017)
PPTX
A slightly advanced introduction to node.js
PPT
nodejs_at_a_glance.ppt
PPT
nodejs_at_a_glance, understanding java script
PDF
NodeJS for Beginner
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
PPTX
NodeJS - Server Side JS
PPTX
Unit 1 Express J for mean stack and mern
PPTX
PPTX
Node.js: A Guided Tour
PPTX
concept of server-side JavaScript / JS Framework: NODEJS
Node.js - A practical introduction (v2)
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Introduction to node.js By Ahmed Assaf
Scalable network applications, event-driven - Node JS
Introduction to Node.js
Starting with Node.js
Introduction to node.js
Introduction to Node (15th May 2017)
A slightly advanced introduction to node.js
nodejs_at_a_glance.ppt
nodejs_at_a_glance, understanding java script
NodeJS for Beginner
A language for the Internet: Why JavaScript and Node.js is right for Internet...
NodeJS - Server Side JS
Unit 1 Express J for mean stack and mern
Node.js: A Guided Tour
concept of server-side JavaScript / JS Framework: NODEJS
Ad

More from Bareen Shaikh (12)

PDF
Express Generator.pdf
PDF
Middleware.pdf
PDF
ExpressJS-Introduction.pdf
PDF
Express JS-Routingmethod.pdf
PPTX
FS_module_functions.pptx
PPTX
File System.pptx
PDF
Web Server.pdf
PDF
NPM.pdf
PDF
NodeJs Modules1.pdf
PDF
NodeJs Modules.pdf
PDF
Introduction to Node JS2.pdf
PDF
Introduction to Node JS.pdf
Express Generator.pdf
Middleware.pdf
ExpressJS-Introduction.pdf
Express JS-Routingmethod.pdf
FS_module_functions.pptx
File System.pptx
Web Server.pdf
NPM.pdf
NodeJs Modules1.pdf
NodeJs Modules.pdf
Introduction to Node JS2.pdf
Introduction to Node JS.pdf
Ad

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Electronic commerce courselecture one. Pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
cuic standard and advanced reporting.pdf
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
DevOps & Developer Experience Summer BBQ
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Event Presentation Google Cloud Next Extended 2025
PPTX
Big Data Technologies - Introduction.pptx
PDF
Advanced IT Governance
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
madgavkar20181017ppt McKinsey Presentation.pdf
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Electronic commerce courselecture one. Pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
20250228 LYD VKU AI Blended-Learning.pptx
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
cuic standard and advanced reporting.pdf
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
DevOps & Developer Experience Summer BBQ
Sensors and Actuators in IoT Systems using pdf
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Event Presentation Google Cloud Next Extended 2025
Big Data Technologies - Introduction.pptx
Advanced IT Governance
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation

Introduction to Node JS1.pdf

  • 1. Prepared By: Prof. Bareen Shaikh Department of Computer Science, MIT ACSC, ALNDI(D), PUNE
  • 2. The following tools/SDK are required for developing a Node.js application on any platform.  Node.js  Node Package Manager (NPM)  IDE (Integrated Development Environment) or TextEditor Note: NPM (Node Package Manager) is included in Node.js installation
  • 13.  Node.js files contain tasks that will be executed on certain events  A typical event is someone trying to access a port on the server  Node.js files must be initiated on the server before having any effect  Node.js files have extension ".js"
  • 14. A Node.js application consists of the following three important components −  Import required modules − Use the require directive to load Node.js modules.  Create server − A server which will listen to client's requests similar to Apache HTTP Server.  Read request and return response − The server created in an earlier step will read the HTTP request made by the client which can be a browser or a console and return the response.
  • 15.  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");
  • 16.  Step 2 - Create Server Use the created http instance and call http.createServer() method to create a server instance http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/HTML}); response.end('Hello Worldn'); }).listen(8080); console.log('Server running…”);
  • 17. var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content- Type': 'text/html'}); res.end('Hello World!'); }).listen(8080); Note:- create a filename.js file and type above program of “Hello World” Save file at c:usersfoldername
  • 18.  Open command prompt C:usersfoldernamenode filename.js Server running…  Now here your computer works as a server  Open browser in address bar type https://localhost:8080
  • 19.  Callback is an asynchronous equivalent for a function  A callback function is called at the completion of a given task  All the APIs of Node are written in such a way that they support callbacks. For example A function to read a file may start reading file and return the control to the execution environment immediately so that the next instruction can be executed. Once file I/O is complete, it will call the callback function while passing the callback function, the content of the file as a parameter. So there is no blocking or wait for File I/O.  This makes Node.js highly scalable, as it can process a high number of requests without waiting for any function to return results.
  • 20.  Create a input file filename.txt  Write some content in it  Create .js file  Write following code in it var fp = require(‘fs'); var data = fp.readFileSync(‘filename.txt'); console.log(data.toString()); console.log("Program Ended");  Run the above node in command prompt.
  • 21.  Create a input file filename.txt  Write some content in it  Create .js file  Write following code in it var fp = require(‘fp'); fp.readFile(‘filename.txt', function (err, data) { if (err) return console.error(err); console.log(data.toString()); }); console.log("Program Ended");  Run the above node in command prompt.  Program ended
  • 22. Blocking Non Blocking  program blocks reads the file and then only it proceeds to end the program.  blocking program executes very much in sequence.  program does not wait for file reading and proceeds to print "Program Ended" and at the same time, the program without blocking continues reading the file.  non-blocking programs do not execute in sequence