SlideShare a Scribd company logo
Server Side Programming
                Using Node.JS


               Ana-Maria Daneliuc
                  Bogdan Gaza


TW2011
$whoarewe


         Students at Faculty of Computer Science


                ana.daneliuc@info.uaic.ro
                bogdan.gaza@info.uaic.ro




TW2011
JavaScript


TW2011
Java is to JavaScript
            Like ham is to hamster




TW2011
JavaScript

         • Language of the Internet
         • Scripting language (interpreted)
         • Client side - usually run by the browser
         • Object oriented
         • Event driven
TW2011
JavaScript

         • Growing in popularity
         • Big companies spend a lot of $$$ to
           improve JavaScript
         • Probably will become a very popular
           language



TW2011
JavaScript
         • Until recent no clear - server side
           JavaScript console interpreter
         • Event driven on the server side also
         • Code sharing
         • All fast evented network servers were
           written in C/C++


TW2011
Node.JS
         Server Side JavaScript




TW2011
Node.js
         • Event driven I/O framework
         • Build upon V8 engine
         • Server Side (includes system calls +
           different modules)
         • Intended for writing scalable network
           programs
         • Written in C/C++ and JavaScript
TW2011
V8
TW2011
V8 JavaScript Engine

         • JavaScript VM used by Google Chrome
         • Written by one of the leading VM engineers
           with 20 years of building VMs - Lars Bak
         • The last VM written by Lars Bak - improved
           JavaScript 20x times.



TW2011
V8 JavaScript Engine

         • JavaScript to assembler
         • Improved garbage collector
         • Independent from Google Chrome
         • Limitations: No bytecode/No threads/No
           processes


TW2011
Non Blocking


TW2011
Blocking




     puts("Enter your name: ");
     var name = gets();
     puts("Name: " + name);




TW2011
Non-Blocking - Node.js way




         puts("Enter your name: ");
         gets(function(name){
             puts("Name: " + name);
         });




TW2011
Remember
                                                     Select
                                                     From the “Retele”



                      Node.js
                                                     Course

                                                     aka explain select
                                                     say about poll/epoll




         When receiving data (from network / disk /
         another source) there must be a callback

                         Data is received
            Data                             Event
           Source                            loop



                                                 CallBack



                                              User
                                            Function

TW2011
Non-blocking vs threaded




TW2011
Non-blocking vs threaded




TW2011
Node.js - Hello World


         var http = require('http');
         http.createServer(function (req, res) {
           res.writeHead(200, {'Content-Type': 'text/plain'});
           res.end('Hello Worldn');
         }).listen(8124, "127.0.0.1");
         console.log('Server running at http://127.0.0.1:8124/');




TW2011
Why use Node.js?


TW2011
Real time web
          applications


TW2011
Ajax

         • Asynchronous JavaScript and XML
         • Method to load data asynchronously
         • Uses XMLHttpRequest object (from JS)
         • Nearly real time

TW2011
Step 1




                  Loading
          Web
                            Page
         Server




TW2011
Step 2




                     Done

          Web
                                 Page
         Server   Ajax Request




TW2011
Step 3




                     Done

          Web
                                 Page
         Server   Ajax Request




TW2011
Step 4




                     Done

          Web
                                 Page
         Server   Ajax Request




TW2011
Step 5




                               Done

          Web
                                                Page
         Server             Ajax Request




                  For another request goto step 1
TW2011
Comet

         Long-lived HTTP connections
         Reduce latency
         Messages are passed from the server to the
         client
         PUSH


TW2011
Step 1




                  Loading
          Web
                            Page
         Server




TW2011
Step 2




                       Done

          Web
                                    Page
         Server   Long lived HTTP




TW2011
Step 3


          Event


                       Done

          Web
                                    Page
         Server   Long lived HTTP




TW2011
Step 4




                       Done

          Web
                                    Page
         Server   Long lived HTTP




TW2011
Step 5




                       Done

          Web
                                    Page
         Server   Long lived HTTP




TW2011
Step 6




                                Done

          Web
                                                Page
         Server            Long lived HTTP




                  For another request goto step 1
TW2011
WebSockets

         • Use TCP sockets from the browser
         • Update web page 40 times / s
         • API is work in progress
         • Not supported by all the modern browsers

TW2011
Ajax vs Comet vs WebSockets
         Ajax      Comet     WebSockets




TW2011
DEMO


TW2011
Q/A

TW2011
Thanks!


TW2011

More Related Content

KEY
Resin Outperforms NginX
PDF
Java EE Servlet/JSP Tutorial- Cookbook 2
PDF
Java EE 7, what's in it for me?
PPTX
HTTP/2 : why upgrading the web? - apidays Paris
PDF
Realtime web application with java
PDF
11.Open Data Protocol(ODATA)
PDF
Servlet and JSP
PDF
Play Framework: async I/O with Java and Scala
Resin Outperforms NginX
Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE 7, what's in it for me?
HTTP/2 : why upgrading the web? - apidays Paris
Realtime web application with java
11.Open Data Protocol(ODATA)
Servlet and JSP
Play Framework: async I/O with Java and Scala

What's hot (20)

PPTX
WebSocket protocol
PDF
Jetty Continuation - 이상민
PDF
Jetty 9 – The Next Generation Servlet Container
PDF
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
PDF
Server-Side Programming Primer
PDF
Vert.x – The problem of real-time data binding
PPTX
Play + scala + reactive mongo
PDF
4 JVM Web Frameworks
PPTX
vlavrynovych - WebSockets Presentation
KEY
Plone Deployment (PloneConf Edition)
PDF
Tips for going fast in a slow world: Michael May at OSCON 2015
PPT
Introduction to node.js aka NodeJS
PPTX
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
PPTX
HTML5 WebSocket Introduction
KEY
Plone Deployment Secrets & Tricks
PDF
COScheduler
PPTX
Road to sbt 1.0 paved with server
PDF
A Gentle Introduction to Functions-as-a-Service
PDF
Asynchronous web apps with the Play Framework 2.0
PPTX
Batching and Java EE (jdk.io)
WebSocket protocol
Jetty Continuation - 이상민
Jetty 9 – The Next Generation Servlet Container
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Server-Side Programming Primer
Vert.x – The problem of real-time data binding
Play + scala + reactive mongo
4 JVM Web Frameworks
vlavrynovych - WebSockets Presentation
Plone Deployment (PloneConf Edition)
Tips for going fast in a slow world: Michael May at OSCON 2015
Introduction to node.js aka NodeJS
HTML5 Real Time and WebSocket Code Lab (SFHTML5, GTUGSF)
HTML5 WebSocket Introduction
Plone Deployment Secrets & Tricks
COScheduler
Road to sbt 1.0 paved with server
A Gentle Introduction to Functions-as-a-Service
Asynchronous web apps with the Play Framework 2.0
Batching and Java EE (jdk.io)
Ad

Viewers also liked (6)

PDF
De la validarea formularelor Web la porcii verzi (utilizarea automatelor in c...
PDF
Pagini web mai rapide
PDF
Javascript, Do you speak it!
PPT
Frontline 2.3
PPT
Alec Williams - Author Allies, Poet Partners and Story Stars: Working with Cr...
 
PPTX
JPSSE - Partido State University
De la validarea formularelor Web la porcii verzi (utilizarea automatelor in c...
Pagini web mai rapide
Javascript, Do you speak it!
Frontline 2.3
Alec Williams - Author Allies, Poet Partners and Story Stars: Working with Cr...
 
JPSSE - Partido State University
Ad

Similar to [TW] Node.js (20)

DOC
Tutorial Solution
KEY
Web Application SG
PDF
Comet with node.js and V8
PPT
Script Fragmentation - Stephan Chenette - OWASP/RSA 2008
PDF
Javascript Views, Client-side or Server-side with NodeJS
PDF
Indroduction to Web Application
PPTX
Servlet & jsp
PDF
Unit 02: Web Technologies (2/2)
PPTX
Don't call us - we'll push - on cross tier push architecture (NLJUG JFall 201...
PDF
HWIOS Websocket CMS explained
PDF
node.js for front-end developers
KEY
Modern Web Technologies — Jerusalem Web Professionals, January 2011
KEY
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...
PDF
Ajax Push For Revolutionary Enterprise Applications
PDF
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
PDF
Unit 02: Web Technologies (1/2)
PPTX
User Interface Patterns and Nuxeo
PDF
Html6 forgotten in html5
PDF
Developing realtime apps with Drupal and NodeJS
PDF
HTML Online Course HTML Course Online online html courses html online training
Tutorial Solution
Web Application SG
Comet with node.js and V8
Script Fragmentation - Stephan Chenette - OWASP/RSA 2008
Javascript Views, Client-side or Server-side with NodeJS
Indroduction to Web Application
Servlet & jsp
Unit 02: Web Technologies (2/2)
Don't call us - we'll push - on cross tier push architecture (NLJUG JFall 201...
HWIOS Websocket CMS explained
node.js for front-end developers
Modern Web Technologies — Jerusalem Web Professionals, January 2011
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...
Ajax Push For Revolutionary Enterprise Applications
Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemo...
Unit 02: Web Technologies (1/2)
User Interface Patterns and Nuxeo
Html6 forgotten in html5
Developing realtime apps with Drupal and NodeJS
HTML Online Course HTML Course Online online html courses html online training

More from Bogdan Gaza (8)

PDF
Weightlifting at SimplySocial
PDF
Understanding and measuring web performance
PDF
[CLIW] Web testing
PDF
[TW] CSS Files Optimization
PDF
Fosdem2011
PDF
RailsAdmin - the right way of doing data administration with Rails 3
PDF
De ce sa nu folosim Ruby On Rails?
KEY
NoSQL in the context of Social Web
Weightlifting at SimplySocial
Understanding and measuring web performance
[CLIW] Web testing
[TW] CSS Files Optimization
Fosdem2011
RailsAdmin - the right way of doing data administration with Rails 3
De ce sa nu folosim Ruby On Rails?
NoSQL in the context of Social Web

[TW] Node.js

  • 1. Server Side Programming Using Node.JS Ana-Maria Daneliuc Bogdan Gaza TW2011
  • 2. $whoarewe Students at Faculty of Computer Science ana.daneliuc@info.uaic.ro bogdan.gaza@info.uaic.ro TW2011
  • 4. Java is to JavaScript Like ham is to hamster TW2011
  • 5. JavaScript • Language of the Internet • Scripting language (interpreted) • Client side - usually run by the browser • Object oriented • Event driven TW2011
  • 6. JavaScript • Growing in popularity • Big companies spend a lot of $$$ to improve JavaScript • Probably will become a very popular language TW2011
  • 7. JavaScript • Until recent no clear - server side JavaScript console interpreter • Event driven on the server side also • Code sharing • All fast evented network servers were written in C/C++ TW2011
  • 8. Node.JS Server Side JavaScript TW2011
  • 9. Node.js • Event driven I/O framework • Build upon V8 engine • Server Side (includes system calls + different modules) • Intended for writing scalable network programs • Written in C/C++ and JavaScript TW2011
  • 11. V8 JavaScript Engine • JavaScript VM used by Google Chrome • Written by one of the leading VM engineers with 20 years of building VMs - Lars Bak • The last VM written by Lars Bak - improved JavaScript 20x times. TW2011
  • 12. V8 JavaScript Engine • JavaScript to assembler • Improved garbage collector • Independent from Google Chrome • Limitations: No bytecode/No threads/No processes TW2011
  • 14. Blocking puts("Enter your name: "); var name = gets(); puts("Name: " + name); TW2011
  • 15. Non-Blocking - Node.js way puts("Enter your name: "); gets(function(name){ puts("Name: " + name); }); TW2011
  • 16. Remember Select From the “Retele” Node.js Course aka explain select say about poll/epoll When receiving data (from network / disk / another source) there must be a callback Data is received Data Event Source loop CallBack User Function TW2011
  • 19. Node.js - Hello World var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/'); TW2011
  • 21. Real time web applications TW2011
  • 22. Ajax • Asynchronous JavaScript and XML • Method to load data asynchronously • Uses XMLHttpRequest object (from JS) • Nearly real time TW2011
  • 23. Step 1 Loading Web Page Server TW2011
  • 24. Step 2 Done Web Page Server Ajax Request TW2011
  • 25. Step 3 Done Web Page Server Ajax Request TW2011
  • 26. Step 4 Done Web Page Server Ajax Request TW2011
  • 27. Step 5 Done Web Page Server Ajax Request For another request goto step 1 TW2011
  • 28. Comet Long-lived HTTP connections Reduce latency Messages are passed from the server to the client PUSH TW2011
  • 29. Step 1 Loading Web Page Server TW2011
  • 30. Step 2 Done Web Page Server Long lived HTTP TW2011
  • 31. Step 3 Event Done Web Page Server Long lived HTTP TW2011
  • 32. Step 4 Done Web Page Server Long lived HTTP TW2011
  • 33. Step 5 Done Web Page Server Long lived HTTP TW2011
  • 34. Step 6 Done Web Page Server Long lived HTTP For another request goto step 1 TW2011
  • 35. WebSockets • Use TCP sockets from the browser • Update web page 40 times / s • API is work in progress • Not supported by all the modern browsers TW2011
  • 36. Ajax vs Comet vs WebSockets Ajax Comet WebSockets TW2011

Editor's Notes