SlideShare a Scribd company logo
1 of 26
Download to read offline
NODE JS INTRODUCTION
Vatsal Shah
Software Embedded Engineer
Deeps Technology
www.vatsalshah.in
Introduction: Basic
 In simple words Node.js is ‘server-side JavaScript’.
 In not-so-simple words Node.js is a high-performance network
applications framework, well optimized for high concurrent
environments.
 It’s a command line tool.
 In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written JavaScript. It is
40% JS and 60% C++.
 From the official site:
‘Node's goal is to provide an easy way to build scalable network programs’
- (from nodejs.org!)
11/16/2016
2
Vatsal Shah | Node Js
Why node.js ?
 Non Blocking I/O
 V8 Java script Engine
 Single Thread with Event Loop
 40,025 modules
 Windows, Linux, Mac
 1 Language for Frontend and Backend
 Active community
11/16/2016
3
Vatsal Shah | Node Js
Why node.js ?
Build Fast!
 JS on server and client allows
for more code reuse
 A lite stack (quick create-test
cycle)
 Large number of offerings for
web app creation
11/16/2016
4
Vatsal Shah | Node Js
Why node.js ?
 JS across stack allows easier
refactoring
 Smaller codebase
 See #1 (Build Fast!)
Adapt Fast!
11/16/2016
5
Vatsal Shah | Node Js
Why node.js ?
Run Fast!  Fast V8 Engine
 Great I/O performance with
event loop!
 Small number of layers
11/16/2016
6
Vatsal Shah | Node Js
Why node.js use event-based?
In a normal process cycle the web server while processing the request
will have to wait for the IO operations and thus blocking the next
request to be processed.
Node.JS process each request as events, The server doesn’t wait for
the IO operation to complete while it can handle other request at the
same time.
When the IO operation of first request is completed it will call-back
the server to complete the request.
11/16/2016
7
Vatsal Shah | Node Js
HTTP Method
 GET
 POST
 PUT
 DELETE
 GET => Read
 POST => Create
 PUT => Update
 DELETE => Delete
11/16/2016
8
Vatsal Shah | Node Js
Node.js Event Loop
11/16/2016
9
Vatsal Shah | Node Js
There are a couple of implications of this apparently very simple and basic model
• Avoid synchronous code at all costs because it blocks the event loop
• Which means: callbacks, callbacks, and more callbacks
Blocking vs. Non-Blocking
Example :: Read data from file and show data
11/16/2016
10
Vatsal Shah | Node Js
Blocking
Read data from file
Show data
Do other tasks
var data = fs.readFileSync( “test.txt” );
console.log( data );
console.log( “Do other tasks” );
11/16/2016
11
Vatsal Shah | Node Js
Non-Blocking
 Read data from file
When read data completed, show data
 Do other tasks
fs.readFile( “test.txt”, function( err, data ) {
console.log(data);
});
11/16/2016
12
Vatsal Shah | Node Js
Node.js Modules
 https://npmjs.org/
 # of modules = 1,21,943
11/16/2016
13
Vatsal Shah | Node Js
Modules
 $npm install <module name>
 Modules allow Node to be extended (act as libaries)
 We can include a module with the global require function, require(‘module’)
 Node provides core modules that can be included by their name:
 File System – require(‘fs’)
 Http – require(‘http’)
 Utilities – require(‘util’)
11/16/2016
14
Vatsal Shah | Node Js
Modules
 We can also break our application up into modules and require
them using a file path:
 ‘/’ (absolute path), ‘./’ and ‘../’ (relative to calling file)
 Any valid type can be exported from a module by assigning it to
module.exports
11/16/2016
15
Vatsal Shah | Node Js
NPM Versions
 Var Versions (version [Major].[Minor].[Patch]):
 = (default), >, <, >=, <=
 * most recent version
 1.2.3 – 2.3.4 version greater than 1.2.3 and less than 2.3.4
 ~1.2.3 most recent patch version greater than or equal to 1.2.3 (>=1.2.3 <1.3.0)
 ^1.2.3 most recent minor version greater than or equal to 1.2.3 (>=1.2.3 <2.0.0)
11/16/2016
16
Vatsal Shah | Node Js
NPM Commands
 Common npm commands:
 npm init initialize a package.json file
 npm install <package name> -g install a package, if –g option is given package
will be installed as a global, --save and --save-dev will add package to your dependencies
 npm install install packages listed in package.json
 npm ls –g listed local packages (without –g) or global packages (with –g)
 npm update <package name> update a package
11/16/2016
17
Vatsal Shah | Node Js
File package.json
 First, we need to create a package.json file for our app
 Contains metadata for our app and lists the dependencies
 Package.json Interactive Guide
Project informations
 Name
 Version
 Dépendances
 Licence
 Main file
Etc...
11/16/2016
18
Vatsal Shah | Node Js
Example-1: Getting Started & Hello World
 Install/build Node.js.
 (Yes! Windows installer is available!)
 Open your favorite editor and start typing JavaScript.
 When you are done, open cmd/terminal and type this:
node YOUR_FILE.js
 Here is a simple example, which prints ‘hello world’
var sys = require sys ;
setTimeout(function(){
sys.puts world ;},3000 ;
sys.puts hello ;
//it prints hello first and waits for 3 seconds and then prints world
11/16/2016
19
Vatsal Shah | Node Js
Node.js Ecosystem
 Node.js heavily relies on modules, in previous examples require keyword
loaded the http & net modules.
 Creating a module is easy, just put your JavaScript code in a separate js
file and include it in your code by using keyword require, like:
var modulex = require ./modulex ;
 Libraries in Node.js are called packages and they can be installed by
typing
npm install package_name ; //package should be available in npm registry @
nmpjs.org
 NPM (Node Package Manager) comes bundled with Node.js installation.
11/16/2016
20
Vatsal Shah | Node Js
Example -2 &3 (HTTP Server & TCP Server)
 Following code creates an HTTP Server and prints ‘Hello World’ on the browser:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn'); }).listen(5000, "127.0.0.1");
 Here is an example of a simple TCP server which listens on port 6000 and echoes whatever you send it:
var net = require('net');
net.createServer(function (socket) {
socket.write("Echo serverrn");
socket.pipe(socket); }).listen(6000, "127.0.0.1");
11/16/2016
21
Vatsal Shah | Node Js
Example-4: Lets connect to a DB (MongoDB)
 Install mongojs using npm, a mongoDB driver for Node.js
npm install mongojs
 Code to retrieve all the documents from a collection:
var db = require("mongojs")
.connect("localhost:27017/test", ['test']);
db.test.find({}, function(err, posts) {
if( err || !posts) console.log("No posts found");
else posts.forEach( function(post) {
console.log(post);
});
});
11/16/2016
22
Vatsal Shah | Node Js
When to use it ?
 Chat/Messaging
 Real-time Applications
 High Concurrency Applications
 Coordinators
 Web application
 Streaming server
 Fast file upload client
 Any Real-time data apps
 Anything with high I/O
11/16/2016
23
Vatsal Shah | Node Js
Who is using Node.js in production?
11/16/2016
24
Vatsal Shah | Node Js
Getting Started
 http://nodejs.org/ and Download tar.gz
 Extract to any directory
 $ ./configure && make install
11/16/2016
25
Vatsal Shah | Node Js
Thank You 

More Related Content

What's hot

Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Node.js, Uma breve introdução
Node.js, Uma breve introduçãoNode.js, Uma breve introdução
Node.js, Uma breve introduçãoPablo Feijó
 
Node JS Crash Course
Node JS Crash CourseNode JS Crash Course
Node JS Crash CourseHaim Michael
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentationThanh Tuong
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST APIFabien Vauchelles
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS Ganesh Kondal
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JSCakra Danu Sedayu
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 

What's hot (20)

Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Node ppt
Node pptNode ppt
Node ppt
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Node.js, Uma breve introdução
Node.js, Uma breve introduçãoNode.js, Uma breve introdução
Node.js, Uma breve introdução
 
Node JS Crash Course
Node JS Crash CourseNode JS Crash Course
Node JS Crash Course
 
Node.js Basics
Node.js Basics Node.js Basics
Node.js Basics
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 
Express JS
Express JSExpress JS
Express JS
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Express js
Express jsExpress js
Express js
 
React
React React
React
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
Spring boot
Spring bootSpring boot
Spring boot
 

Viewers also liked

Poster IOTROBOT vatsalnshah_ec_indusuniversity
Poster IOTROBOT vatsalnshah_ec_indusuniversityPoster IOTROBOT vatsalnshah_ec_indusuniversity
Poster IOTROBOT vatsalnshah_ec_indusuniversityVatsal N Shah
 
Presentation IOT Robot
Presentation IOT RobotPresentation IOT Robot
Presentation IOT RobotVatsal N Shah
 
From Hello World to Real World - Container Days Boston 2016
From Hello World to Real World - Container Days Boston 2016From Hello World to Real World - Container Days Boston 2016
From Hello World to Real World - Container Days Boston 2016Shannon Williams
 
Project ideas ece students
Project ideas ece studentsProject ideas ece students
Project ideas ece studentsVatsal N Shah
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
iot report 3 (2)
iot report 3 (2)iot report 3 (2)
iot report 3 (2)AISWARYA T
 
project report on IoT
project report on IoTproject report on IoT
project report on IoTAnshul Sahu
 
Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。Tatsuya Tobioka
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureColin Mackay
 
EmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image AnalysisEmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image Analysisjeresig
 
Report Automatic led emergency light
Report Automatic led emergency lightReport Automatic led emergency light
Report Automatic led emergency lightVatsal N Shah
 
pick-and-place-robot
pick-and-place-robotpick-and-place-robot
pick-and-place-robotSuchit Moon
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 

Viewers also liked (20)

Poster IOTROBOT vatsalnshah_ec_indusuniversity
Poster IOTROBOT vatsalnshah_ec_indusuniversityPoster IOTROBOT vatsalnshah_ec_indusuniversity
Poster IOTROBOT vatsalnshah_ec_indusuniversity
 
Presentation IOT Robot
Presentation IOT RobotPresentation IOT Robot
Presentation IOT Robot
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
From Hello World to Real World - Container Days Boston 2016
From Hello World to Real World - Container Days Boston 2016From Hello World to Real World - Container Days Boston 2016
From Hello World to Real World - Container Days Boston 2016
 
Project ideas ece students
Project ideas ece studentsProject ideas ece students
Project ideas ece students
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
iot report 3 (2)
iot report 3 (2)iot report 3 (2)
iot report 3 (2)
 
project report on IoT
project report on IoTproject report on IoT
project report on IoT
 
Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。
 
Node js meetup
Node js meetupNode js meetup
Node js meetup
 
Report IOT Robot
Report IOT RobotReport IOT Robot
Report IOT Robot
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 
EmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image AnalysisEmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image Analysis
 
Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 
Report Automatic led emergency light
Report Automatic led emergency lightReport Automatic led emergency light
Report Automatic led emergency light
 
Am fm transmitter
Am fm transmitterAm fm transmitter
Am fm transmitter
 
Search and rescue
Search and rescueSearch and rescue
Search and rescue
 
pick-and-place-robot
pick-and-place-robotpick-and-place-robot
pick-and-place-robot
 
Node JS
Node JSNode JS
Node JS
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 

Similar to Node JS Introduction: Non-Blocking I/O and Event Loop

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 projectLaurence Svekis ✔
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed AssafAhmed Assaf
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comVan-Duyet Le
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginnersEnoch Joshua
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopleffen
 
Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10David Ashton
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsWinston Hsieh
 
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 beginnersLaurence Svekis ✔
 
Introducing Node.js in an Oracle technology environment (including hands-on)
Introducing Node.js in an Oracle technology environment (including hands-on)Introducing Node.js in an Oracle technology environment (including hands-on)
Introducing Node.js in an Oracle technology environment (including hands-on)Lucas Jellema
 
Node js (runtime environment + js library) platform
Node js (runtime environment + js library) platformNode js (runtime environment + js library) platform
Node js (runtime environment + js library) platformSreenivas Kappala
 

Similar to Node JS Introduction: Non-Blocking I/O and Event Loop (20)

Nodejs
NodejsNodejs
Nodejs
 
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
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 
Node J pdf.docx
Node J pdf.docxNode J pdf.docx
Node J pdf.docx
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshop
 
Proposal
ProposalProposal
Proposal
 
NodeJS @ ACS
NodeJS @ ACSNodeJS @ ACS
NodeJS @ ACS
 
Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10Halton Software Peer 2 Peer Meetup #10
Halton Software Peer 2 Peer Meetup #10
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
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
Node jsNode js
Node js
 
Introducing Node.js in an Oracle technology environment (including hands-on)
Introducing Node.js in an Oracle technology environment (including hands-on)Introducing Node.js in an Oracle technology environment (including hands-on)
Introducing Node.js in an Oracle technology environment (including hands-on)
 
Ferrara Linux Day 2011
Ferrara Linux Day 2011Ferrara Linux Day 2011
Ferrara Linux Day 2011
 
Node js first look - 2016
Node js first look - 2016Node js first look - 2016
Node js first look - 2016
 
Node js (runtime environment + js library) platform
Node js (runtime environment + js library) platformNode js (runtime environment + js library) platform
Node js (runtime environment + js library) platform
 
Nodejs
NodejsNodejs
Nodejs
 

More from Vatsal N Shah

Machine Learning Project - Default credit card clients
Machine Learning Project - Default credit card clients Machine Learning Project - Default credit card clients
Machine Learning Project - Default credit card clients Vatsal N Shah
 
I am sharing my journey with Indus University and Indus Family. Read Page No:...
I am sharing my journey with Indus University and Indus Family. Read Page No:...I am sharing my journey with Indus University and Indus Family. Read Page No:...
I am sharing my journey with Indus University and Indus Family. Read Page No:...Vatsal N Shah
 
Floor cleaning robot(autonomus mannual) vatsal shah-ec_4th year
Floor cleaning robot(autonomus mannual)  vatsal shah-ec_4th yearFloor cleaning robot(autonomus mannual)  vatsal shah-ec_4th year
Floor cleaning robot(autonomus mannual) vatsal shah-ec_4th yearVatsal N Shah
 
Raspbeery Pi : An Introduction
Raspbeery Pi : An IntroductionRaspbeery Pi : An Introduction
Raspbeery Pi : An IntroductionVatsal N Shah
 
Report Remote communication of Robotic module using lifa
Report Remote communication of Robotic module using lifaReport Remote communication of Robotic module using lifa
Report Remote communication of Robotic module using lifaVatsal N Shah
 
Floor cleaning robot report vatsal shah_ec_7th sem
Floor cleaning robot report vatsal shah_ec_7th semFloor cleaning robot report vatsal shah_ec_7th sem
Floor cleaning robot report vatsal shah_ec_7th semVatsal N Shah
 
IRC Magazine Issue_1
IRC Magazine Issue_1IRC Magazine Issue_1
IRC Magazine Issue_1Vatsal N Shah
 
Advanced wheel chair vatsal shah
Advanced wheel chair   vatsal shah Advanced wheel chair   vatsal shah
Advanced wheel chair vatsal shah Vatsal N Shah
 
Configuring lifa for remote communication using web architecture
Configuring lifa for remote communication using web architectureConfiguring lifa for remote communication using web architecture
Configuring lifa for remote communication using web architectureVatsal N Shah
 
Control robotic module using LIFA
Control robotic module using LIFAControl robotic module using LIFA
Control robotic module using LIFAVatsal N Shah
 
E-sync-Revista-Editon-1
E-sync-Revista-Editon-1E-sync-Revista-Editon-1
E-sync-Revista-Editon-1Vatsal N Shah
 
GSM based lcd dsiplay
GSM based lcd dsiplayGSM based lcd dsiplay
GSM based lcd dsiplayVatsal N Shah
 
Project report format
Project report formatProject report format
Project report formatVatsal N Shah
 
Abstract - Interfacing 5 x7 matrix led display to 8051
Abstract - Interfacing 5 x7 matrix led display to 8051 Abstract - Interfacing 5 x7 matrix led display to 8051
Abstract - Interfacing 5 x7 matrix led display to 8051 Vatsal N Shah
 
5x7 matrix led display
5x7 matrix led display 5x7 matrix led display
5x7 matrix led display Vatsal N Shah
 
A seminar report on flex sensor
A seminar report on flex sensor A seminar report on flex sensor
A seminar report on flex sensor Vatsal N Shah
 

More from Vatsal N Shah (20)

Machine Learning Project - Default credit card clients
Machine Learning Project - Default credit card clients Machine Learning Project - Default credit card clients
Machine Learning Project - Default credit card clients
 
I am sharing my journey with Indus University and Indus Family. Read Page No:...
I am sharing my journey with Indus University and Indus Family. Read Page No:...I am sharing my journey with Indus University and Indus Family. Read Page No:...
I am sharing my journey with Indus University and Indus Family. Read Page No:...
 
Floor cleaning robot(autonomus mannual) vatsal shah-ec_4th year
Floor cleaning robot(autonomus mannual)  vatsal shah-ec_4th yearFloor cleaning robot(autonomus mannual)  vatsal shah-ec_4th year
Floor cleaning robot(autonomus mannual) vatsal shah-ec_4th year
 
Projects
ProjectsProjects
Projects
 
Raspbeery Pi : An Introduction
Raspbeery Pi : An IntroductionRaspbeery Pi : An Introduction
Raspbeery Pi : An Introduction
 
Report Remote communication of Robotic module using lifa
Report Remote communication of Robotic module using lifaReport Remote communication of Robotic module using lifa
Report Remote communication of Robotic module using lifa
 
Floor cleaning robot report vatsal shah_ec_7th sem
Floor cleaning robot report vatsal shah_ec_7th semFloor cleaning robot report vatsal shah_ec_7th sem
Floor cleaning robot report vatsal shah_ec_7th sem
 
IRC Magazine Issue_1
IRC Magazine Issue_1IRC Magazine Issue_1
IRC Magazine Issue_1
 
Advanced wheel chair vatsal shah
Advanced wheel chair   vatsal shah Advanced wheel chair   vatsal shah
Advanced wheel chair vatsal shah
 
Configuring lifa for remote communication using web architecture
Configuring lifa for remote communication using web architectureConfiguring lifa for remote communication using web architecture
Configuring lifa for remote communication using web architecture
 
Control robotic module using LIFA
Control robotic module using LIFAControl robotic module using LIFA
Control robotic module using LIFA
 
Trapatt diode
Trapatt diode Trapatt diode
Trapatt diode
 
Telemedicine
Telemedicine Telemedicine
Telemedicine
 
E-sync-Revista-Editon-1
E-sync-Revista-Editon-1E-sync-Revista-Editon-1
E-sync-Revista-Editon-1
 
GSM based lcd dsiplay
GSM based lcd dsiplayGSM based lcd dsiplay
GSM based lcd dsiplay
 
Project report format
Project report formatProject report format
Project report format
 
Abstract - Interfacing 5 x7 matrix led display to 8051
Abstract - Interfacing 5 x7 matrix led display to 8051 Abstract - Interfacing 5 x7 matrix led display to 8051
Abstract - Interfacing 5 x7 matrix led display to 8051
 
5x7 matrix led display
5x7 matrix led display 5x7 matrix led display
5x7 matrix led display
 
A seminar report on flex sensor
A seminar report on flex sensor A seminar report on flex sensor
A seminar report on flex sensor
 
Flex sensor
Flex sensor   Flex sensor
Flex sensor
 

Recently uploaded

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 

Recently uploaded (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 

Node JS Introduction: Non-Blocking I/O and Event Loop

  • 1. NODE JS INTRODUCTION Vatsal Shah Software Embedded Engineer Deeps Technology www.vatsalshah.in
  • 2. Introduction: Basic  In simple words Node.js is ‘server-side JavaScript’.  In not-so-simple words Node.js is a high-performance network applications framework, well optimized for high concurrent environments.  It’s a command line tool.  In ‘Node.js’ , ‘.js’ doesn’t mean that its solely written JavaScript. It is 40% JS and 60% C++.  From the official site: ‘Node's goal is to provide an easy way to build scalable network programs’ - (from nodejs.org!) 11/16/2016 2 Vatsal Shah | Node Js
  • 3. Why node.js ?  Non Blocking I/O  V8 Java script Engine  Single Thread with Event Loop  40,025 modules  Windows, Linux, Mac  1 Language for Frontend and Backend  Active community 11/16/2016 3 Vatsal Shah | Node Js
  • 4. Why node.js ? Build Fast!  JS on server and client allows for more code reuse  A lite stack (quick create-test cycle)  Large number of offerings for web app creation 11/16/2016 4 Vatsal Shah | Node Js
  • 5. Why node.js ?  JS across stack allows easier refactoring  Smaller codebase  See #1 (Build Fast!) Adapt Fast! 11/16/2016 5 Vatsal Shah | Node Js
  • 6. Why node.js ? Run Fast!  Fast V8 Engine  Great I/O performance with event loop!  Small number of layers 11/16/2016 6 Vatsal Shah | Node Js
  • 7. Why node.js use event-based? In a normal process cycle the web server while processing the request will have to wait for the IO operations and thus blocking the next request to be processed. Node.JS process each request as events, The server doesn’t wait for the IO operation to complete while it can handle other request at the same time. When the IO operation of first request is completed it will call-back the server to complete the request. 11/16/2016 7 Vatsal Shah | Node Js
  • 8. HTTP Method  GET  POST  PUT  DELETE  GET => Read  POST => Create  PUT => Update  DELETE => Delete 11/16/2016 8 Vatsal Shah | Node Js
  • 9. Node.js Event Loop 11/16/2016 9 Vatsal Shah | Node Js There are a couple of implications of this apparently very simple and basic model • Avoid synchronous code at all costs because it blocks the event loop • Which means: callbacks, callbacks, and more callbacks
  • 10. Blocking vs. Non-Blocking Example :: Read data from file and show data 11/16/2016 10 Vatsal Shah | Node Js
  • 11. Blocking Read data from file Show data Do other tasks var data = fs.readFileSync( “test.txt” ); console.log( data ); console.log( “Do other tasks” ); 11/16/2016 11 Vatsal Shah | Node Js
  • 12. Non-Blocking  Read data from file When read data completed, show data  Do other tasks fs.readFile( “test.txt”, function( err, data ) { console.log(data); }); 11/16/2016 12 Vatsal Shah | Node Js
  • 13. Node.js Modules  https://npmjs.org/  # of modules = 1,21,943 11/16/2016 13 Vatsal Shah | Node Js
  • 14. Modules  $npm install <module name>  Modules allow Node to be extended (act as libaries)  We can include a module with the global require function, require(‘module’)  Node provides core modules that can be included by their name:  File System – require(‘fs’)  Http – require(‘http’)  Utilities – require(‘util’) 11/16/2016 14 Vatsal Shah | Node Js
  • 15. Modules  We can also break our application up into modules and require them using a file path:  ‘/’ (absolute path), ‘./’ and ‘../’ (relative to calling file)  Any valid type can be exported from a module by assigning it to module.exports 11/16/2016 15 Vatsal Shah | Node Js
  • 16. NPM Versions  Var Versions (version [Major].[Minor].[Patch]):  = (default), >, <, >=, <=  * most recent version  1.2.3 – 2.3.4 version greater than 1.2.3 and less than 2.3.4  ~1.2.3 most recent patch version greater than or equal to 1.2.3 (>=1.2.3 <1.3.0)  ^1.2.3 most recent minor version greater than or equal to 1.2.3 (>=1.2.3 <2.0.0) 11/16/2016 16 Vatsal Shah | Node Js
  • 17. NPM Commands  Common npm commands:  npm init initialize a package.json file  npm install <package name> -g install a package, if –g option is given package will be installed as a global, --save and --save-dev will add package to your dependencies  npm install install packages listed in package.json  npm ls –g listed local packages (without –g) or global packages (with –g)  npm update <package name> update a package 11/16/2016 17 Vatsal Shah | Node Js
  • 18. File package.json  First, we need to create a package.json file for our app  Contains metadata for our app and lists the dependencies  Package.json Interactive Guide Project informations  Name  Version  Dépendances  Licence  Main file Etc... 11/16/2016 18 Vatsal Shah | Node Js
  • 19. Example-1: Getting Started & Hello World  Install/build Node.js.  (Yes! Windows installer is available!)  Open your favorite editor and start typing JavaScript.  When you are done, open cmd/terminal and type this: node YOUR_FILE.js  Here is a simple example, which prints ‘hello world’ var sys = require sys ; setTimeout(function(){ sys.puts world ;},3000 ; sys.puts hello ; //it prints hello first and waits for 3 seconds and then prints world 11/16/2016 19 Vatsal Shah | Node Js
  • 20. Node.js Ecosystem  Node.js heavily relies on modules, in previous examples require keyword loaded the http & net modules.  Creating a module is easy, just put your JavaScript code in a separate js file and include it in your code by using keyword require, like: var modulex = require ./modulex ;  Libraries in Node.js are called packages and they can be installed by typing npm install package_name ; //package should be available in npm registry @ nmpjs.org  NPM (Node Package Manager) comes bundled with Node.js installation. 11/16/2016 20 Vatsal Shah | Node Js
  • 21. Example -2 &3 (HTTP Server & TCP Server)  Following code creates an HTTP Server and prints ‘Hello World’ on the browser: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(5000, "127.0.0.1");  Here is an example of a simple TCP server which listens on port 6000 and echoes whatever you send it: var net = require('net'); net.createServer(function (socket) { socket.write("Echo serverrn"); socket.pipe(socket); }).listen(6000, "127.0.0.1"); 11/16/2016 21 Vatsal Shah | Node Js
  • 22. Example-4: Lets connect to a DB (MongoDB)  Install mongojs using npm, a mongoDB driver for Node.js npm install mongojs  Code to retrieve all the documents from a collection: var db = require("mongojs") .connect("localhost:27017/test", ['test']); db.test.find({}, function(err, posts) { if( err || !posts) console.log("No posts found"); else posts.forEach( function(post) { console.log(post); }); }); 11/16/2016 22 Vatsal Shah | Node Js
  • 23. When to use it ?  Chat/Messaging  Real-time Applications  High Concurrency Applications  Coordinators  Web application  Streaming server  Fast file upload client  Any Real-time data apps  Anything with high I/O 11/16/2016 23 Vatsal Shah | Node Js
  • 24. Who is using Node.js in production? 11/16/2016 24 Vatsal Shah | Node Js
  • 25. Getting Started  http://nodejs.org/ and Download tar.gz  Extract to any directory  $ ./configure && make install 11/16/2016 25 Vatsal Shah | Node Js