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
Introduction to Node js for beginners + game project
PPTX
Introduction to node.js
PPTX
U4-01-Node JS.pptxweasrdtfyhg[]"Piuytrhedfyguhijokpl
PPTX
Node.js Workshop - Sela SDP 2015
PPTX
Node.js web-based Example :Run a local server in order to start using node.js...
PPTX
Introducing Node.js in an Oracle technology environment (including hands-on)
PPT
A java servers
PDF
A java servers
Introduction to Node js for beginners + game project
Introduction to node.js
U4-01-Node JS.pptxweasrdtfyhg[]"Piuytrhedfyguhijokpl
Node.js Workshop - Sela SDP 2015
Node.js web-based Example :Run a local server in order to start using node.js...
Introducing Node.js in an Oracle technology environment (including hands-on)
A java servers
A java servers

Similar to Introduction to Node JS1.pdf (20)

PDF
PPT
Node js beginner
PPT
nodejs_at_a_glance.ppt
PPT
nodejs_at_a_glance, understanding java script
PDF
introduction to node js kndoendenendjndj
PPTX
NodeJS guide for beginners
PPTX
Scalable network applications, event-driven - Node JS
PDF
Web Server and how we can design app in C#
PPTX
Introduction to Node.js
PPT
Exploring Node.jS
DOCX
Node js getting started
PDF
Release with confidence
ODP
An Overview of Node.js
PDF
OSDC.no 2015 introduction to node.js workshop
PDF
Play framework
PDF
Play Framework: async I/O with Java and Scala
PPTX
RoR guide_p1
PPTX
Local SQLite Database with Node for beginners
PPT
Setting up the hyperledger composer in ubuntu
Node js beginner
nodejs_at_a_glance.ppt
nodejs_at_a_glance, understanding java script
introduction to node js kndoendenendjndj
NodeJS guide for beginners
Scalable network applications, event-driven - Node JS
Web Server and how we can design app in C#
Introduction to Node.js
Exploring Node.jS
Node js getting started
Release with confidence
An Overview of Node.js
OSDC.no 2015 introduction to node.js workshop
Play framework
Play Framework: async I/O with Java and Scala
RoR guide_p1
Local SQLite Database with Node for beginners
Setting up the hyperledger composer in ubuntu
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)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Big Data Technologies - Introduction.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25-Week II
20250228 LYD VKU AI Blended-Learning.pptx
Spectroscopy.pptx food analysis technology
Network Security Unit 5.pdf for BCA BBA.
Per capita expenditure prediction using model stacking based on satellite ima...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation theory and applications.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Advanced methodologies resolving dimensionality complications for autism neur...
Big Data Technologies - Introduction.pptx
A comparative analysis of optical character recognition models for extracting...

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