SlideShare une entreprise Scribd logo
1  sur  23
The Server-side JavaScript
Dss PRAKASH
WHAT TO EXPECT AHEAD….
 Introduction
 Some Theory
 A couple of weird diagrams
 2 Pictures showing unbelievable benchmarks
 Some stuff from Internet
Dss PRAKASH
DEVELOPMENT FOR THE WEB
 Data is generated on the server, transferred to the client and
displayed by the browser
 Server Side technologies include PHP, JSP, ASP.net, Rails,
and also Node.js
Dss PRAKASH
NODE JS – WHAT IS IT ..?
 JavaScript is well known for client-side scripts running inside
the browser.
 Node.js is JavaScript running on the server-side .
 Node.js create isomorphic applications, i.e. applications that
are build with the same language on the back and front-ends.
Dss PRAKASH
BACKGROUND
 V8 is an open source JavaScript engine developed by Google.
Its written in C++ and is used in Google Chrome Browser.
 Node.js runs on V8.
 It was created by Ryan Dahl in 2009.
 Is still in Beta phase. Latest version is v0.12.4
 Is Open Source. It runs well on Linux systems, can also run
on Windows systems.
 If you have worked on EventMachine (Ruby) or Python’s
Twisted or Perl’s AnyEvent framework then following
presentation is going to be very easy.
Dss PRAKASH
INTRODUCTION: BASIC
 In simple words Node.js is ‘server-side JavaScript’.
 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!)
Dss PRAKASH
INTRODUCTION: ADVANCED
 Node.js uses an event-driven, non-blocking I/O model,
which makes it lightweight. (from nodejs.org!)
 It makes use of event-loops via JavaScript’s callback
functionality to implement the non-blocking I/O.
 Programs for Node.js are written in JavaScript but not in the
same JavaScript we are use to. There is no DOM
implementation provided by Node.js, i.e. you can not do this:
var element = document.getElementById(“elementId”);
 Everything inside Node.js runs in a single-thread.
Dss PRAKASH
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’
Dss PRAKASH
SOME THEORY: EVENT-LOOPS
 Event-loops are the core of event-driven programming, almost all the
UI programs use event-loops to track the user event, for example:
Clicks, Ajax Requests etc.
Client
Event loop
(Single thread)
C++ Threadpool
(worker threads)
Clients send HTTP requests
to Node.js server
An Event-loop is woken up by OS,
passes request and response objects
to the thread-pool
Long-running jobs run
on worker threads
Response is sent
back to main thread
via callback
Event loop returns
result to client
Dss PRAKASH
SOME THEORY: NON-BLOCKING I/O
 Traditional I/O
var result = db.query(“select x from table_Y”);
doSomethingWith(result); //wait for result!
doSomethingWithOutResult(); //execution is blocked!
 Non-traditional, Non-blocking I/O
db.query(“select x from table_Y”,function (result){
doSomethingWith(result); //wait for result!
});
doSomethingWithOutResult(); //executes without any delay!
Dss PRAKASH
WHAT CAN YOU DO WITH NODE.JS ?
 You can create an HTTP server and print ‘hello world’ on the
browser in just 4 lines of JavaScript.
 You can create a TCP server similar to HTTP server, in just 4
lines of JavaScript.
 You can create a DNS server.
 You can create a Static File Server.
 You can create a Web Chat Application like GTalk in the
browser.
 Node.js can also be used for creating online games,
collaboration tools or anything which sends updates to the
user in real-time.
Dss PRAKASH
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");
Dss PRAKASH
Call method to create a new HTTP
server
Use require keyword to load a module
define anonymous callback that
handles request event
start accepting
connections on port
and hostname
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.
Dss PRAKASH
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);
});
});
Dss PRAKASH
WHEN TO USE NODE.JS?
 Node.js is good for creating streaming based real-time
services, web chat applications, static file servers etc.
 If you need high level concurrency and not worried about CPU-
cycles.
 If you are great at writing JavaScript code because then you
can use the same language at both the places: server-side
and client-side.
 More can be found at:
http://stackoverflow.com/questions/5062614/how-to-decide-
when-to-use-nodejs
Dss PRAKASH
EXAMPLE-5: TWITTER STREAMING
 Install nTwitter module using npm:
Npm install ntwitter
 Code:
var twitter = require('ntwitter');
var twit = new twitter({
consumer_key: ‘c_key’,
consumer_secret: ‘c_secret’,
access_token_key: ‘token_key’,
access_token_secret: ‘token_secret’});
twit.stream('statuses/sample', function(stream) {
stream.on('data', function (data) {
console.log(data); });
});
Dss PRAKASH
Dss PRAKASH
SOME NODE.JS BENCHMARKS
Taken from: http://code.google.com/p/node-js-vs-
apache-php-benchmark/wiki/Tests
A benchmark between Apache+PHP and
node.js, shows the response time for 1000
concurrent connections making 10,000
requests each, for 5 tests.
Taken from:
http://nodejs.org/jsconf2010.pdf
The benchmark shows the
response time in milli-secs for 4
evented servers.
Dss PRAKASH
WHEN TO NOT USE NODE.JS
 When you are doing heavy and CPU intensive calculations on
server side, because event-loops are CPU hungry.
 Node.js API is still in beta, it keeps on changing a lot from one
revision to another and there is a very little backward
compatibility. Most of the packages are also unstable.
Therefore is not yet production ready.
 Node.js is a no match for enterprise level application
frameworks like Spring(java), Django(python), Symfony(php)
etc. Applications written on such platforms are meant to be
highly user interactive and involve complex business logic.
 Read further on disadvantages of Node.js on Quora:
http://www.quora.com/What-are-the-disadvantages-of-using-
Node-js
Dss PRAKASH
APPENDIX-1: WHO IS USING NODE.JS IN
PRODUCTION?
 Yahoo! : iPad App Livestand uses Yahoo! Manhattan
framework which is based on Node.js.
 LinkedIn : LinkedIn uses a combination of Node.js and
MongoDB for its mobile platform. iOS and Android apps are
based on it.
 eBay : Uses Node.js along with ql.io to help application
developers in improving eBay’s end user experience.
 Dow Jones : The WSJ Social front-end is written completely in
Node.js, using Express.js, and many other modules.
 Complete list can be found at:
https://github.com/joyent/node/wiki/Projects,-Applications,-and-
Companies-Using-Node
Dss PRAKASH
APPENDIX-2: RESOURCE TO GET STARTED
 Watch this video at Youtube:
http://www.youtube.com/watch?v=jo_B4LTHi3I
 Read the free O’reilly Book ‘Up and Running with Node.js’ @
http://ofps.oreilly.com/titles/9781449398583/
 Visit www.nodejs.org for Info/News about Node.js
 Watch Node.js tutorials @ http://nodetuts.com/
 For Info on MongoDB:
http://www.mongodb.org/display/DOCS/Home
 For anything else Google!
Dss PRAKASH
APPENDIX-3: SOME GOOD MODULES
 Express – to make things simpler e.g. syntax, DB
connections.
 Jade – HTML template system
 Socket.IO – to create real-time apps
 Nodemon – to monitor Node.js and push change
automatically
 CoffeeScript – for easier JavaScript development
 Find out more about some widely used Node.js modules at:
http://blog.nodejitsu.com/top-node-module-creators
Dss PRAKASH
Dss PRAKASH

Contenu connexe

Tendances

Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppEdureka!
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaNurul Ferdous
 
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 Web Apps @ ebay scale
Node.js Web Apps @ ebay scaleNode.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scaleDmytro Semenov
 
Why You Should Use MERN Stack for Startup Apps?
Why You Should Use MERN Stack for Startup Apps?Why You Should Use MERN Stack for Startup Apps?
Why You Should Use MERN Stack for Startup Apps?Pixel Crayons
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS drupalcampest
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Devang Garach
 
Bringing Interactivity to Your Drupal Site with Node.js Integration
Bringing Interactivity to Your Drupal Site with Node.js IntegrationBringing Interactivity to Your Drupal Site with Node.js Integration
Bringing Interactivity to Your Drupal Site with Node.js IntegrationAcquia
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015jbandi
 
Introduction to NPM and building CLI Tools with Node.js
Introduction to NPM and building CLI Tools with Node.jsIntroduction to NPM and building CLI Tools with Node.js
Introduction to NPM and building CLI Tools with Node.jsSuroor Wijdan
 
Understand How Node.js and Core Features Works
Understand How Node.js and Core Features WorksUnderstand How Node.js and Core Features Works
Understand How Node.js and Core Features WorksHengki Sihombing
 
Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?jbandi
 
Node.js In The Enterprise - A Primer
Node.js In The Enterprise - A PrimerNode.js In The Enterprise - A Primer
Node.js In The Enterprise - A PrimerNaveen S.R
 

Tendances (20)

Node js
Node jsNode js
Node js
 
Node JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web AppNode JS Express: Steps to Create Restful Web App
Node JS Express: Steps to Create Restful Web App
 
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, DhakaJavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
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.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scaleNode.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scale
 
Why You Should Use MERN Stack for Startup Apps?
Why You Should Use MERN Stack for Startup Apps?Why You Should Use MERN Stack for Startup Apps?
Why You Should Use MERN Stack for Startup Apps?
 
Node js Global Packages
Node js Global PackagesNode js Global Packages
Node js Global Packages
 
(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
 
Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS Developing realtime apps with Drupal and NodeJS
Developing realtime apps with Drupal and NodeJS
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7
 
Bringing Interactivity to Your Drupal Site with Node.js Integration
Bringing Interactivity to Your Drupal Site with Node.js IntegrationBringing Interactivity to Your Drupal Site with Node.js Integration
Bringing Interactivity to Your Drupal Site with Node.js Integration
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
Treinamento frontend
Treinamento frontendTreinamento frontend
Treinamento frontend
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to NPM and building CLI Tools with Node.js
Introduction to NPM and building CLI Tools with Node.jsIntroduction to NPM and building CLI Tools with Node.js
Introduction to NPM and building CLI Tools with Node.js
 
Understand How Node.js and Core Features Works
Understand How Node.js and Core Features WorksUnderstand How Node.js and Core Features Works
Understand How Node.js and Core Features Works
 
Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?
 
Node.js In The Enterprise - A Primer
Node.js In The Enterprise - A PrimerNode.js In The Enterprise - A Primer
Node.js In The Enterprise - A Primer
 

En vedette

лицей29сент2011педсовет
лицей29сент2011педсоветлицей29сент2011педсовет
лицей29сент2011педсоветardabiev
 
Werkloze jongeren hebben litteken voor het leven
Werkloze jongeren hebben litteken voor het levenWerkloze jongeren hebben litteken voor het leven
Werkloze jongeren hebben litteken voor het levenid Plein BV
 
Southern Arc Minerals Corporate Presentation
Southern Arc Minerals Corporate PresentationSouthern Arc Minerals Corporate Presentation
Southern Arc Minerals Corporate PresentationSouthernArc
 
phonegap with angular js for freshers
phonegap with angular js for freshers    phonegap with angular js for freshers
phonegap with angular js for freshers dssprakash
 
Pictavo Yearbook Software Guide
Pictavo Yearbook Software GuidePictavo Yearbook Software Guide
Pictavo Yearbook Software GuideYearbookLife
 
Yearbook Recognition and Dedication Ads
Yearbook Recognition and Dedication AdsYearbook Recognition and Dedication Ads
Yearbook Recognition and Dedication AdsYearbookLife
 
School Yearbook Theme
School Yearbook ThemeSchool Yearbook Theme
School Yearbook ThemeYearbookLife
 
High School Yearbook Cover options
High School Yearbook Cover optionsHigh School Yearbook Cover options
High School Yearbook Cover optionsYearbookLife
 
Vision,Mission,Strategy and Leadership.
Vision,Mission,Strategy and Leadership.Vision,Mission,Strategy and Leadership.
Vision,Mission,Strategy and Leadership.Sonia Verma
 
School Yearbook Staff Monthly Calendar
School Yearbook Staff Monthly CalendarSchool Yearbook Staff Monthly Calendar
School Yearbook Staff Monthly CalendarYearbookLife
 
02 01 아이디어_발상법-김용경[최종]
02 01 아이디어_발상법-김용경[최종]02 01 아이디어_발상법-김용경[최종]
02 01 아이디어_발상법-김용경[최종]Seonghee Jeon
 
Women entrepreneurship in india by sonia verma
Women entrepreneurship in india by sonia vermaWomen entrepreneurship in india by sonia verma
Women entrepreneurship in india by sonia vermaSonia Verma
 
Sensation and Perception
Sensation and PerceptionSensation and Perception
Sensation and PerceptionSophia Vadlit
 

En vedette (17)

лицей29сент2011педсовет
лицей29сент2011педсоветлицей29сент2011педсовет
лицей29сент2011педсовет
 
Werkloze jongeren hebben litteken voor het leven
Werkloze jongeren hebben litteken voor het levenWerkloze jongeren hebben litteken voor het leven
Werkloze jongeren hebben litteken voor het leven
 
Southern Arc Minerals Corporate Presentation
Southern Arc Minerals Corporate PresentationSouthern Arc Minerals Corporate Presentation
Southern Arc Minerals Corporate Presentation
 
A-Evropa
A-EvropaA-Evropa
A-Evropa
 
phonegap with angular js for freshers
phonegap with angular js for freshers    phonegap with angular js for freshers
phonegap with angular js for freshers
 
Pictavo Yearbook Software Guide
Pictavo Yearbook Software GuidePictavo Yearbook Software Guide
Pictavo Yearbook Software Guide
 
Yearbook Recognition and Dedication Ads
Yearbook Recognition and Dedication AdsYearbook Recognition and Dedication Ads
Yearbook Recognition and Dedication Ads
 
School Yearbook Theme
School Yearbook ThemeSchool Yearbook Theme
School Yearbook Theme
 
Yearbook Sales
Yearbook SalesYearbook Sales
Yearbook Sales
 
High School Yearbook Cover options
High School Yearbook Cover optionsHigh School Yearbook Cover options
High School Yearbook Cover options
 
Yearbook Coverage
Yearbook CoverageYearbook Coverage
Yearbook Coverage
 
Vision,Mission,Strategy and Leadership.
Vision,Mission,Strategy and Leadership.Vision,Mission,Strategy and Leadership.
Vision,Mission,Strategy and Leadership.
 
School Yearbook Staff Monthly Calendar
School Yearbook Staff Monthly CalendarSchool Yearbook Staff Monthly Calendar
School Yearbook Staff Monthly Calendar
 
02 01 아이디어_발상법-김용경[최종]
02 01 아이디어_발상법-김용경[최종]02 01 아이디어_발상법-김용경[최종]
02 01 아이디어_발상법-김용경[최종]
 
Baking
BakingBaking
Baking
 
Women entrepreneurship in india by sonia verma
Women entrepreneurship in india by sonia vermaWomen entrepreneurship in india by sonia verma
Women entrepreneurship in india by sonia verma
 
Sensation and Perception
Sensation and PerceptionSensation and Perception
Sensation and Perception
 

Similaire à Nodejs

Similaire à Nodejs (20)

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
 
Proposal
ProposalProposal
Proposal
 
Node.js Web Development .pdf
Node.js Web Development .pdfNode.js Web Development .pdf
Node.js Web Development .pdf
 
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
 
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
 
Node.js.pdf
Node.js.pdfNode.js.pdf
Node.js.pdf
 
Ferrara Linux Day 2011
Ferrara Linux Day 2011Ferrara Linux Day 2011
Ferrara Linux Day 2011
 
Node js
Node jsNode js
Node js
 
Nodejs
NodejsNodejs
Nodejs
 
An overview of node.js
An overview of node.jsAn overview of node.js
An overview of node.js
 
Nodejs
NodejsNodejs
Nodejs
 
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
 
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous  Blocking or synchronous.pdfNode Js Non-blocking or asynchronous  Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
 
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other ThingsI Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
02 Node introduction
02 Node introduction02 Node introduction
02 Node introduction
 
Starting with Node.js
Starting with Node.jsStarting with Node.js
Starting with Node.js
 

Dernier

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
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
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
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
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 

Dernier (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
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
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
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
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 

Nodejs

  • 2. WHAT TO EXPECT AHEAD….  Introduction  Some Theory  A couple of weird diagrams  2 Pictures showing unbelievable benchmarks  Some stuff from Internet Dss PRAKASH
  • 3. DEVELOPMENT FOR THE WEB  Data is generated on the server, transferred to the client and displayed by the browser  Server Side technologies include PHP, JSP, ASP.net, Rails, and also Node.js Dss PRAKASH
  • 4. NODE JS – WHAT IS IT ..?  JavaScript is well known for client-side scripts running inside the browser.  Node.js is JavaScript running on the server-side .  Node.js create isomorphic applications, i.e. applications that are build with the same language on the back and front-ends. Dss PRAKASH
  • 5. BACKGROUND  V8 is an open source JavaScript engine developed by Google. Its written in C++ and is used in Google Chrome Browser.  Node.js runs on V8.  It was created by Ryan Dahl in 2009.  Is still in Beta phase. Latest version is v0.12.4  Is Open Source. It runs well on Linux systems, can also run on Windows systems.  If you have worked on EventMachine (Ruby) or Python’s Twisted or Perl’s AnyEvent framework then following presentation is going to be very easy. Dss PRAKASH
  • 6. INTRODUCTION: BASIC  In simple words Node.js is ‘server-side JavaScript’.  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!) Dss PRAKASH
  • 7. INTRODUCTION: ADVANCED  Node.js uses an event-driven, non-blocking I/O model, which makes it lightweight. (from nodejs.org!)  It makes use of event-loops via JavaScript’s callback functionality to implement the non-blocking I/O.  Programs for Node.js are written in JavaScript but not in the same JavaScript we are use to. There is no DOM implementation provided by Node.js, i.e. you can not do this: var element = document.getElementById(“elementId”);  Everything inside Node.js runs in a single-thread. Dss PRAKASH
  • 8. 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’ Dss PRAKASH
  • 9. SOME THEORY: EVENT-LOOPS  Event-loops are the core of event-driven programming, almost all the UI programs use event-loops to track the user event, for example: Clicks, Ajax Requests etc. Client Event loop (Single thread) C++ Threadpool (worker threads) Clients send HTTP requests to Node.js server An Event-loop is woken up by OS, passes request and response objects to the thread-pool Long-running jobs run on worker threads Response is sent back to main thread via callback Event loop returns result to client Dss PRAKASH
  • 10. SOME THEORY: NON-BLOCKING I/O  Traditional I/O var result = db.query(“select x from table_Y”); doSomethingWith(result); //wait for result! doSomethingWithOutResult(); //execution is blocked!  Non-traditional, Non-blocking I/O db.query(“select x from table_Y”,function (result){ doSomethingWith(result); //wait for result! }); doSomethingWithOutResult(); //executes without any delay! Dss PRAKASH
  • 11. WHAT CAN YOU DO WITH NODE.JS ?  You can create an HTTP server and print ‘hello world’ on the browser in just 4 lines of JavaScript.  You can create a TCP server similar to HTTP server, in just 4 lines of JavaScript.  You can create a DNS server.  You can create a Static File Server.  You can create a Web Chat Application like GTalk in the browser.  Node.js can also be used for creating online games, collaboration tools or anything which sends updates to the user in real-time. Dss PRAKASH
  • 12. 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"); Dss PRAKASH Call method to create a new HTTP server Use require keyword to load a module define anonymous callback that handles request event start accepting connections on port and hostname
  • 13. 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. Dss PRAKASH
  • 14. 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); }); }); Dss PRAKASH
  • 15. WHEN TO USE NODE.JS?  Node.js is good for creating streaming based real-time services, web chat applications, static file servers etc.  If you need high level concurrency and not worried about CPU- cycles.  If you are great at writing JavaScript code because then you can use the same language at both the places: server-side and client-side.  More can be found at: http://stackoverflow.com/questions/5062614/how-to-decide- when-to-use-nodejs Dss PRAKASH
  • 16. EXAMPLE-5: TWITTER STREAMING  Install nTwitter module using npm: Npm install ntwitter  Code: var twitter = require('ntwitter'); var twit = new twitter({ consumer_key: ‘c_key’, consumer_secret: ‘c_secret’, access_token_key: ‘token_key’, access_token_secret: ‘token_secret’}); twit.stream('statuses/sample', function(stream) { stream.on('data', function (data) { console.log(data); }); }); Dss PRAKASH
  • 18. SOME NODE.JS BENCHMARKS Taken from: http://code.google.com/p/node-js-vs- apache-php-benchmark/wiki/Tests A benchmark between Apache+PHP and node.js, shows the response time for 1000 concurrent connections making 10,000 requests each, for 5 tests. Taken from: http://nodejs.org/jsconf2010.pdf The benchmark shows the response time in milli-secs for 4 evented servers. Dss PRAKASH
  • 19. WHEN TO NOT USE NODE.JS  When you are doing heavy and CPU intensive calculations on server side, because event-loops are CPU hungry.  Node.js API is still in beta, it keeps on changing a lot from one revision to another and there is a very little backward compatibility. Most of the packages are also unstable. Therefore is not yet production ready.  Node.js is a no match for enterprise level application frameworks like Spring(java), Django(python), Symfony(php) etc. Applications written on such platforms are meant to be highly user interactive and involve complex business logic.  Read further on disadvantages of Node.js on Quora: http://www.quora.com/What-are-the-disadvantages-of-using- Node-js Dss PRAKASH
  • 20. APPENDIX-1: WHO IS USING NODE.JS IN PRODUCTION?  Yahoo! : iPad App Livestand uses Yahoo! Manhattan framework which is based on Node.js.  LinkedIn : LinkedIn uses a combination of Node.js and MongoDB for its mobile platform. iOS and Android apps are based on it.  eBay : Uses Node.js along with ql.io to help application developers in improving eBay’s end user experience.  Dow Jones : The WSJ Social front-end is written completely in Node.js, using Express.js, and many other modules.  Complete list can be found at: https://github.com/joyent/node/wiki/Projects,-Applications,-and- Companies-Using-Node Dss PRAKASH
  • 21. APPENDIX-2: RESOURCE TO GET STARTED  Watch this video at Youtube: http://www.youtube.com/watch?v=jo_B4LTHi3I  Read the free O’reilly Book ‘Up and Running with Node.js’ @ http://ofps.oreilly.com/titles/9781449398583/  Visit www.nodejs.org for Info/News about Node.js  Watch Node.js tutorials @ http://nodetuts.com/  For Info on MongoDB: http://www.mongodb.org/display/DOCS/Home  For anything else Google! Dss PRAKASH
  • 22. APPENDIX-3: SOME GOOD MODULES  Express – to make things simpler e.g. syntax, DB connections.  Jade – HTML template system  Socket.IO – to create real-time apps  Nodemon – to monitor Node.js and push change automatically  CoffeeScript – for easier JavaScript development  Find out more about some widely used Node.js modules at: http://blog.nodejitsu.com/top-node-module-creators Dss PRAKASH