SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
Building web apps with node.js,
      socket.io, knockout.js and zombie.js
      Iván Loire
      ivan@iloire.com

      Freelance node.js developer

      http://iloire.com
      http://letsnode.com




Sunday, March 25, 2012
real-time                         javascript
    ninja rockstar dev
                         Why is everybody talking about Node.js?
                                      sockets

               What are we node.js developers
                    so excited about?
            cool
                                    startup                              hype
                                                 nodeconf
                                                                        Iván Loire   2
                                                      freelance node.js developer

Sunday, March 25, 2012
What is node.js?

                              .. why should you get into it?


                     an extra framework to learn?
                     please leave me alone...


                                                                                 Iván Loire   3
                                                               freelance node.js developer

Sunday, March 25, 2012
• high performance javascript library for intensive I/O
        operations. (like HTTP)
                                                      - Node.js is not a language.
      • single threaded, event oriented.              - Node.js is not a framework.
                                                      - Node.js is not (just) a web
      • built on Chrome’s Javascript runtime (V8)     server.

                                                      - Node.js will always be simple
      • lightweight, efficient, really fast.          and optimized for speed and high
                                                      concurrency.
      • .. insanely fast.
      • modular. Excellent package manager: NPM


                                                                               Iván Loire   4
                                                             freelance node.js developer

Sunday, March 25, 2012
Why node.js?
      • Ryan Dahl (creator of node.js):
         – “I am not happy with the way web
           servers and apps work
           today” (apache, php, rails, IIS, etc).
         – “We need something faster, highly
           scalable”.
      • Check “History of node”
         – http://www.youtube.com/watch?                - Thanks Ryan!
           v=SAc0vQCC6UQ

                                                                      Iván Loire   5
                                                    freelance node.js developer

Sunday, March 25, 2012
Traditional server
                                           - New thread per request
                                           - The thread is blocked during
                                           long IO operations (red)

                                            When a new http request hits the web server:

                                            1. A new thread is created.
                                            2. Web server connects to database server (tcp
                                            handshake, authentication, etc..)
                                            3. Web server sends SQL query to be executed.
                                            4. Idle.. (database server retrieves data..)
                                            5. Idle... (web server waits for data)
                                            6. Idle... (web server waits for data...)
                                            7. Web server finally gets the data.
                                            8. Web response is returned to the client.



                         image from: http://magnetik.github.com/node-webid-report/

                                                                  Iván Loire          6
                                                freelance node.js developer

Sunday, March 25, 2012
Node.js thesis
                                                                  •   I/O is expensive.. (see left)
                                                                  •   Thread per connection is
                                                                      memory expensive.

                                                                 • POLL: 9 out of 10 servers
                                                                   think they have more
                                                                   interesting things to do
                                                                   than waiting for I/O.

     image: http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/

                                                                                                      Iván Loire   7
                                                                                    freelance node.js developer

Sunday, March 25, 2012
Node.js
                                       - Event loop in a single thread
                                       - Operations are executed
                                       asynchronously (callbacks)

                                                              - Single thread to handle
                                                              callbacks.
                                                              - Ideal for waiting for I/O calls
                                                              (network, filesystem, database)
                                                              - Not ideal for CPU intensive
                                                              operations (it will block) ->
                                                              solution: fork new child process.
                                                              - No thread management
                                                              - No need for synchronization
                                                              - Creating scalable web servers
                                                              is easy



                         image from: http://magnetik.github.com/node-webid-report/

                                                                  Iván Loire              8
                                                freelance node.js developer

Sunday, March 25, 2012
Why are we so excited about node.js?
                                                       - A new programming language is a new way of
                                                       solving problems.
      •   Powerful: Designed for high concurrency.
      •   Real-time: Designed for next generations, real-time web apps (socket.io)
      •   Productivity: Code a high performance web app in a day.
      •   Simple: You don’t need expensive, complicated, heavy and buggy IDE’s.
      •   Easy: Deploys in minutes (git, npm).
      •   Efficient: Node.js uses minimum resources (a few hundred Mb of RAM
          are fine for hosting several node.js processes)
      •   Safe: Don’t worry about shared resources (node.js is single threaded)

                                                   it just works, well and fast!!
                                                                               Iván Loire         9
                                                             freelance node.js developer

Sunday, March 25, 2012
and also...

                  node.js is real..




                             FUN!!
                                                        Iván Loire   10
                                      freelance node.js developer

Sunday, March 25, 2012
Web development with node.js

                              Handling HTTP request is
                                    just I/O right?

                              So node.js should be quite
                                   good on this...


                                                                             Iván Loire   11
                                                           freelance node.js developer

Sunday, March 25, 2012
Web development with node.js
      Ok, I already made the 5 lines web server example
      with node.js. Now... how do I create real web apps?

      •    How do I handle http requests and responses?
      •    How do I parse form and querystring input data?
      •    How do I manage user sessions?
      •    How do I render html? Can I use MVC, views, layouts, etc ?

                                                                     Iván Loire   12
                                                   freelance node.js developer

Sunday, March 25, 2012
Node.js community to the rescue!

      • Hundreds of modules submitted by programmers like you or
        me (hopefully better) !!

          So has anybody created a framework
          to create web apps in node.js yet!??
                                                   well, let’s see...
                                                                Iván Loire   13
                                              freelance node.js developer

Sunday, March 25, 2012
mmmm... YES, someone did!!!
      •    Connect
      •    Express.js <- yes, I heard about this one
      •    Railways.js <- this is rails style right?
      •    Geddy.js
      •    Tower.js
      •    SocketStream (websockets)
      •    ...
                                                               Iván Loire   14
                                             freelance node.js developer

Sunday, March 25, 2012
express.js
      • High performance, high class web development for node.js.
      • Simple, minimalist.              - Express is one the most common node.js web
                                         frameworks out there.
      • Sexy ..really fast.              - It is simple and minimalist.
                                         - If you need anything else, get a module.


       Express is an extra layer of abstraction on top of Node.js
        so you can easily create high performance web servers

      • MVC, session support (in-memory, redis), cookie parsing,
        middleware, view engines (ejs, jade), etc.

                                                                                 Iván Loire   15
                                                               freelance node.js developer

Sunday, March 25, 2012
http://expressjs.com
                                                 Iván Loire   16
                               freelance node.js developer

Sunday, March 25, 2012
In the browser ..
      • Express.js serves HTML pages or render JSON data
        as response (faster, lighter)
      • We need something to actually get the JSON data
        and render the proper UI in the browser.
      • We need a view-model with declarative bindings,
        automatic UI refresh, templating...

                                                something like...

                                                           Iván Loire   17
                                         freelance node.js developer

Sunday, March 25, 2012
knockout.js
      • Rich, responsive display with a clean underlying data
        model.
        – declarative bindinds <span data-bind=”value: msg”></span>
        – automatic UI refresh
        – dependency tracking
        – templating


                                                                  Iván Loire   18
                                                freelance node.js developer

Sunday, March 25, 2012
Knockout.js model binding
                                           - Declarative binding




                                                                Iván Loire   19
                                              freelance node.js developer

Sunday, March 25, 2012
- Define the view-model.
                          - Knockout automatically
                          synchronizes UI when model
                          changes.




                                           Iván Loire   20
                         freelance node.js developer

Sunday, March 25, 2012
Single Page Interface (SPI)
                                                                                           node.js
                                                                                           socket.io

                                               JSON
                                             {msg: ‘hi!’}

                                        - Once we have our view model, we just
        <span data-bind=”value: msg”>   need to push and pull data from and to
                                        the server (by using HTTP or
                                        websockets communication)
        browser
      We update the view-model using JSON                                                web server
      through HTTP or over websockets (faster!)
                                                                                    Iván Loire     21
                                                                  freelance node.js developer

Sunday, March 25, 2012
Example:     directorio.cachirulovalley.com
                                                                - express.js
                                                                - knockout.js
                                                                - redis (db)




                           https://github.com/iloire/cachirulovalleydirectory
                                                                         Iván Loire   22
                                                       freelance node.js developer

Sunday, March 25, 2012
Zombie.js
     from the website (http://zombie.labnotes.org/):
     Insanely fast, headless full-stack testing using
     Node.js
                                 hey!
                                 Why everything is
                                   “INSANELY fast”
                                 in this presentation??


                                                                     Iván Loire   23
                                                   freelance node.js developer

Sunday, March 25, 2012
Zombie.js
      var Browser = require("zombie");

      var assert = require("assert");
                                                                         This code will:
      browser = new Browser() // Load the page from localhost

      browser.visit("http://localhost:3000/", function () {              - Create a new instance of zombie browser
        browser.      // Fill email, password and submit form            - Open url
            fill("email", "zombie@underworld.dead").                     - Find form elements and fill them
            fill("password", "eat-the-living").
                                                                         - Submit form
                                                                         - Read and analyze the response
            pressButton("Sign Me Up!", function() {

             // Form submitted, new page loaded.

                 assert.ok(browser.success);

                 assert.equal(browser.text("title"), "Welcome To Brains Depot");

            })

      });


                                                                                                       Iván Loire   24
                                                                                     freelance node.js developer

Sunday, March 25, 2012
Zombie.js
      • Tests are meant to be fast (or you won’t run them)
            – Zombie.js run your tests on parallel.
      • Zombie.js will trigger the proper client side events
        and will wait for all your asynchronous code to be
        executed.
            – This is good for testing SPI (single page interface) apps


                                                                        Iván Loire   25
                                                      freelance node.js developer

Sunday, March 25, 2012
Similar to zombie.js
      • Phantom.js: (PhantomJS is a headless WebKit
        with JavaScript AP)
      • Selenium: (Unit testing with real browsers)




                                                             Iván Loire   26
                                           freelance node.js developer

Sunday, March 25, 2012
Last but not least...
      • Websockets.
      • Socket.io.
      • Real-time apps.




                                                              Iván Loire   27
                                            freelance node.js developer

Sunday, March 25, 2012
Websockets
      • Bi-directional, full duplex over a single tcp socket.
      • Connection remains open = no tcp handshake
      • Lightweight protocol = no http headers, 2 byte
        overhead
      • Supported on chrome 16, FF 11, IE 10, Opera 10
      • Reducing latency from 150 (http) to 50 ms (sockets)


                                                               Iván Loire   28
                                             freelance node.js developer

Sunday, March 25, 2012
HTTP overhead (for each request)
                             “hello, my name is Chrome, encoding UTF-8...
                             I would like a web page please.”




                         +                          +

                              HTTP Headers                  HTTP Headers
        TCP handshake           (request)                    (response)

                                                                          Iván Loire   29
                                                        freelance node.js developer

Sunday, March 25, 2012
Websockets                  - HTTP handshake negotiated only
                                                          once.
                                                          - 2 bytes overhead
                                                          - Bi-directional full duplex channel.




                                         data + 2 byte overhead


                                      data + 2 byte overhead

       TCP handshake
     (just first request)


                            Browser                                        Server

                                                                         Iván Loire               30
                                                       freelance node.js developer

Sunday, March 25, 2012
socket.io
      • Websockets for the rest of us (even IE!!)
      • Fallback transports:                   Websockets is not fully supported in all
                                               browsers yet.
            –   websockets                                     Some smart people created socket.io, a
                                                               library for cross browsing real-time
            –   flash sockets                                  communication

            –   ajax long polling                              If websockets is available, we will use it. If
                                                               it is not, it will try fallback transports until
            –   ajax streaming                                 one of them works.


            –   iframe
            –   json polling..


                                                                                Iván Loire                31
                                                              freelance node.js developer

Sunday, March 25, 2012
Don’t forget a really fast database


      • open source, high performance, in-memory, key-value
        data store
      • support master-slave replication, pub/sub channels.
      • really fast!                          don’t tell me...
      • if (ACID) durability is not needed... INSANELY FAST!!

                                                                Iván Loire   32
                                              freelance node.js developer

Sunday, March 25, 2012
node.js / socket.io examples
      • Math-Race
            – code: https://github.com/iloire/math-race
            – demo: http://letsnode.com:8090/

                            - Simple game that shows the basics of socket.io
                            and how you can create applications that
                            communicate browsers in real time.




                                                                                           Iván Loire   33
                                                                         freelance node.js developer

Sunday, March 25, 2012
Video:
                         http://www.youtube.com/watch?v=LXbYSJfLUW8



                                                                        Iván Loire   34
                                                      freelance node.js developer

Sunday, March 25, 2012
node.js / socket.io examples
      • Socket-piano
            – Play the piano in remote browsers.
            – code: https://github.com/iloire/socket-piano


                                 Let’s try the demo...




                                                                           Iván Loire   35
                                                         freelance node.js developer

Sunday, March 25, 2012
New generation of low latency mobile
                     web apps

              SenchaTouch2 + node.js + socket.io


                                                         Iván Loire   36
                                       freelance node.js developer

Sunday, March 25, 2012
Video:
                         http://www.youtube.com/watch?v=yyHl4cGOlss

                                                                         Iván Loire   37
                                                       freelance node.js developer

Sunday, March 25, 2012
That’s all folks!
                         Eso es todo amigos!

                           Iván Loire @ivanloire
                            http://iloire.com



                                                                     Iván Loire   38
                                                   freelance node.js developer

Sunday, March 25, 2012

Mais conteúdo relacionado

Mais procurados

Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js ExplainedJeff Kunkle
 
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
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkAarti Parikh
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS Ganesh Kondal
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystemYukti Kaura
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBhargav Anadkat
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting startedTriet Ho
 
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!
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)Chris Cowan
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developerscacois
 
Node.js Crash Course
Node.js Crash CourseNode.js Crash Course
Node.js Crash CourseDavid Neal
 
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
 
Intro to node and non blocking io
Intro to node and non blocking ioIntro to node and non blocking io
Intro to node and non blocking ioAmy Hua
 

Mais procurados (20)

Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js Explained
 
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
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
Nodejs getting started
Nodejs getting startedNodejs getting started
Nodejs getting started
 
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...
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
NodeJS: an Introduction
NodeJS: an IntroductionNodeJS: an Introduction
NodeJS: an Introduction
 
Node.js Crash Course
Node.js Crash CourseNode.js Crash Course
Node.js Crash Course
 
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
 
Intro to node and non blocking io
Intro to node and non blocking ioIntro to node and non blocking io
Intro to node and non blocking io
 
Node
NodeNode
Node
 

Destaque

Realtime MVC with Sails.js
Realtime MVC with Sails.jsRealtime MVC with Sails.js
Realtime MVC with Sails.jsSerdar Dogruyol
 
Efficient use of NodeJS
Efficient use of NodeJSEfficient use of NodeJS
Efficient use of NodeJSYura Bogdanov
 
Angular 2.0: Getting ready
Angular 2.0: Getting readyAngular 2.0: Getting ready
Angular 2.0: Getting readyAxilis
 
Grunt JS - Getting Started With Grunt
Grunt JS - Getting Started With GruntGrunt JS - Getting Started With Grunt
Grunt JS - Getting Started With GruntDouglas Reynolds
 
Introduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devIntroduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devmcantelon
 
Grunt - The JavaScript Task Runner
Grunt - The JavaScript Task RunnerGrunt - The JavaScript Task Runner
Grunt - The JavaScript Task RunnerMohammed Arif
 
Going real time with Socket.io
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.ioArnout Kazemier
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.jsConFoo
 
Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。Tatsuya Tobioka
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Scaling and securing node.js apps
Scaling and securing node.js appsScaling and securing node.js apps
Scaling and securing node.js appsMaciej Lasyk
 
WebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascriptWebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascriptMichele Di Salvatore
 
Real-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisYork Tsai
 
Az információs lánc
Az információs láncAz információs lánc
Az információs láncZoltán Zeman
 
Bing Cashback Marketing Plan
Bing Cashback Marketing PlanBing Cashback Marketing Plan
Bing Cashback Marketing PlanChristina Dick
 
WZ high head slurry pump brochure
WZ high head slurry pump brochureWZ high head slurry pump brochure
WZ high head slurry pump brochureFelix Yu
 

Destaque (20)

Sails js
Sails jsSails js
Sails js
 
Intro to Sails.js
Intro to Sails.jsIntro to Sails.js
Intro to Sails.js
 
Realtime MVC with Sails.js
Realtime MVC with Sails.jsRealtime MVC with Sails.js
Realtime MVC with Sails.js
 
Efficient use of NodeJS
Efficient use of NodeJSEfficient use of NodeJS
Efficient use of NodeJS
 
Socket.IO
Socket.IOSocket.IO
Socket.IO
 
Socket.io (part 1)
Socket.io (part 1)Socket.io (part 1)
Socket.io (part 1)
 
Angular 2.0: Getting ready
Angular 2.0: Getting readyAngular 2.0: Getting ready
Angular 2.0: Getting ready
 
Grunt JS - Getting Started With Grunt
Grunt JS - Getting Started With GruntGrunt JS - Getting Started With Grunt
Grunt JS - Getting Started With Grunt
 
Introduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devIntroduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal dev
 
Grunt - The JavaScript Task Runner
Grunt - The JavaScript Task RunnerGrunt - The JavaScript Task Runner
Grunt - The JavaScript Task Runner
 
Going real time with Socket.io
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.io
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.js
 
Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Scaling and securing node.js apps
Scaling and securing node.js appsScaling and securing node.js apps
Scaling and securing node.js apps
 
WebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascriptWebRTC + Socket.io: building a skype-like video chat with native javascript
WebRTC + Socket.io: building a skype-like video chat with native javascript
 
Real-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and RedisReal-time Web Application with Socket.IO, Node.js, and Redis
Real-time Web Application with Socket.IO, Node.js, and Redis
 
Az információs lánc
Az információs láncAz információs lánc
Az információs lánc
 
Bing Cashback Marketing Plan
Bing Cashback Marketing PlanBing Cashback Marketing Plan
Bing Cashback Marketing Plan
 
WZ high head slurry pump brochure
WZ high head slurry pump brochureWZ high head slurry pump brochure
WZ high head slurry pump brochure
 

Semelhante a Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemotion 2012

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
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tourcacois
 
Deep Dive into Node.js Event Loop.pdf
Deep Dive into Node.js Event Loop.pdfDeep Dive into Node.js Event Loop.pdf
Deep Dive into Node.js Event Loop.pdfShubhamChaurasia88
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVadym Lotar
 
Sfd hanoi2012 nguyen ha duong yang node.js-intro
Sfd hanoi2012 nguyen ha duong yang   node.js-introSfd hanoi2012 nguyen ha duong yang   node.js-intro
Sfd hanoi2012 nguyen ha duong yang node.js-introVu Hung Nguyen
 
Sfd2012Hanoi Nguyễn Hà Dương - Introduction to Node.js
Sfd2012Hanoi Nguyễn Hà Dương - Introduction to Node.jsSfd2012Hanoi Nguyễn Hà Dương - Introduction to Node.js
Sfd2012Hanoi Nguyễn Hà Dương - Introduction to Node.jsVu Hung Nguyen
 
Node.js for .net developers
Node.js for .net developersNode.js for .net developers
Node.js for .net developerskementeus
 
Building real time apps with node.js, socket.io, knockout.js
Building real time apps with node.js, socket.io, knockout.jsBuilding real time apps with node.js, socket.io, knockout.js
Building real time apps with node.js, socket.io, knockout.jsbetabeers
 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrencypgriess
 
OpenSky Infrastructure
OpenSky InfrastructureOpenSky Infrastructure
OpenSky InfrastructureJonathan Wage
 
Introduction to Node JS.pdf
Introduction to Node JS.pdfIntroduction to Node JS.pdf
Introduction to Node JS.pdfBareen Shaikh
 
Node.js meetup at Palo Alto Networks Tel Aviv
Node.js meetup at Palo Alto Networks Tel AvivNode.js meetup at Palo Alto Networks Tel Aviv
Node.js meetup at Palo Alto Networks Tel AvivRon Perlmuter
 
A Journey Begin with Node.js
A Journey Begin with Node.jsA Journey Begin with Node.js
A Journey Begin with Node.jsKhalid Farhan
 
Node.js Enterprise Middleware
Node.js Enterprise MiddlewareNode.js Enterprise Middleware
Node.js Enterprise MiddlewareBehrad Zari
 
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
 
A295 nodejs-knowledge-accelerator
A295   nodejs-knowledge-acceleratorA295   nodejs-knowledge-accelerator
A295 nodejs-knowledge-acceleratorMichael Dawson
 

Semelhante a Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemotion 2012 (20)

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
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
 
Node js internal
Node js internalNode js internal
Node js internal
 
Mini-Training: Node.js
Mini-Training: Node.jsMini-Training: Node.js
Mini-Training: Node.js
 
Deep Dive into Node.js Event Loop.pdf
Deep Dive into Node.js Event Loop.pdfDeep Dive into Node.js Event Loop.pdf
Deep Dive into Node.js Event Loop.pdf
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Sfd hanoi2012 nguyen ha duong yang node.js-intro
Sfd hanoi2012 nguyen ha duong yang   node.js-introSfd hanoi2012 nguyen ha duong yang   node.js-intro
Sfd hanoi2012 nguyen ha duong yang node.js-intro
 
Sfd2012Hanoi Nguyễn Hà Dương - Introduction to Node.js
Sfd2012Hanoi Nguyễn Hà Dương - Introduction to Node.jsSfd2012Hanoi Nguyễn Hà Dương - Introduction to Node.js
Sfd2012Hanoi Nguyễn Hà Dương - Introduction to Node.js
 
Node.js for .net developers
Node.js for .net developersNode.js for .net developers
Node.js for .net developers
 
Building real time apps with node.js, socket.io, knockout.js
Building real time apps with node.js, socket.io, knockout.jsBuilding real time apps with node.js, socket.io, knockout.js
Building real time apps with node.js, socket.io, knockout.js
 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrency
 
02 Node introduction
02 Node introduction02 Node introduction
02 Node introduction
 
OpenSky Infrastructure
OpenSky InfrastructureOpenSky Infrastructure
OpenSky Infrastructure
 
Introduction to Node JS.pdf
Introduction to Node JS.pdfIntroduction to Node JS.pdf
Introduction to Node JS.pdf
 
Node.js meetup at Palo Alto Networks Tel Aviv
Node.js meetup at Palo Alto Networks Tel AvivNode.js meetup at Palo Alto Networks Tel Aviv
Node.js meetup at Palo Alto Networks Tel Aviv
 
A Journey Begin with Node.js
A Journey Begin with Node.jsA Journey Begin with Node.js
A Journey Begin with Node.js
 
Node.js Enterprise Middleware
Node.js Enterprise MiddlewareNode.js Enterprise Middleware
Node.js Enterprise Middleware
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
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
 
A295 nodejs-knowledge-accelerator
A295   nodejs-knowledge-acceleratorA295   nodejs-knowledge-accelerator
A295 nodejs-knowledge-accelerator
 

Último

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Último (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 

Building web apps with node.js, socket.io, knockout.js and zombie.js - Codemotion 2012

  • 1. Building web apps with node.js, socket.io, knockout.js and zombie.js Iván Loire ivan@iloire.com Freelance node.js developer http://iloire.com http://letsnode.com Sunday, March 25, 2012
  • 2. real-time javascript ninja rockstar dev Why is everybody talking about Node.js? sockets What are we node.js developers so excited about? cool startup hype nodeconf Iván Loire 2 freelance node.js developer Sunday, March 25, 2012
  • 3. What is node.js? .. why should you get into it? an extra framework to learn? please leave me alone... Iván Loire 3 freelance node.js developer Sunday, March 25, 2012
  • 4. • high performance javascript library for intensive I/O operations. (like HTTP) - Node.js is not a language. • single threaded, event oriented. - Node.js is not a framework. - Node.js is not (just) a web • built on Chrome’s Javascript runtime (V8) server. - Node.js will always be simple • lightweight, efficient, really fast. and optimized for speed and high concurrency. • .. insanely fast. • modular. Excellent package manager: NPM Iván Loire 4 freelance node.js developer Sunday, March 25, 2012
  • 5. Why node.js? • Ryan Dahl (creator of node.js): – “I am not happy with the way web servers and apps work today” (apache, php, rails, IIS, etc). – “We need something faster, highly scalable”. • Check “History of node” – http://www.youtube.com/watch? - Thanks Ryan! v=SAc0vQCC6UQ Iván Loire 5 freelance node.js developer Sunday, March 25, 2012
  • 6. Traditional server - New thread per request - The thread is blocked during long IO operations (red) When a new http request hits the web server: 1. A new thread is created. 2. Web server connects to database server (tcp handshake, authentication, etc..) 3. Web server sends SQL query to be executed. 4. Idle.. (database server retrieves data..) 5. Idle... (web server waits for data) 6. Idle... (web server waits for data...) 7. Web server finally gets the data. 8. Web response is returned to the client. image from: http://magnetik.github.com/node-webid-report/ Iván Loire 6 freelance node.js developer Sunday, March 25, 2012
  • 7. Node.js thesis • I/O is expensive.. (see left) • Thread per connection is memory expensive. • POLL: 9 out of 10 servers think they have more interesting things to do than waiting for I/O. image: http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/ Iván Loire 7 freelance node.js developer Sunday, March 25, 2012
  • 8. Node.js - Event loop in a single thread - Operations are executed asynchronously (callbacks) - Single thread to handle callbacks. - Ideal for waiting for I/O calls (network, filesystem, database) - Not ideal for CPU intensive operations (it will block) -> solution: fork new child process. - No thread management - No need for synchronization - Creating scalable web servers is easy image from: http://magnetik.github.com/node-webid-report/ Iván Loire 8 freelance node.js developer Sunday, March 25, 2012
  • 9. Why are we so excited about node.js? - A new programming language is a new way of solving problems. • Powerful: Designed for high concurrency. • Real-time: Designed for next generations, real-time web apps (socket.io) • Productivity: Code a high performance web app in a day. • Simple: You don’t need expensive, complicated, heavy and buggy IDE’s. • Easy: Deploys in minutes (git, npm). • Efficient: Node.js uses minimum resources (a few hundred Mb of RAM are fine for hosting several node.js processes) • Safe: Don’t worry about shared resources (node.js is single threaded) it just works, well and fast!! Iván Loire 9 freelance node.js developer Sunday, March 25, 2012
  • 10. and also... node.js is real.. FUN!! Iván Loire 10 freelance node.js developer Sunday, March 25, 2012
  • 11. Web development with node.js Handling HTTP request is just I/O right? So node.js should be quite good on this... Iván Loire 11 freelance node.js developer Sunday, March 25, 2012
  • 12. Web development with node.js Ok, I already made the 5 lines web server example with node.js. Now... how do I create real web apps? • How do I handle http requests and responses? • How do I parse form and querystring input data? • How do I manage user sessions? • How do I render html? Can I use MVC, views, layouts, etc ? Iván Loire 12 freelance node.js developer Sunday, March 25, 2012
  • 13. Node.js community to the rescue! • Hundreds of modules submitted by programmers like you or me (hopefully better) !! So has anybody created a framework to create web apps in node.js yet!?? well, let’s see... Iván Loire 13 freelance node.js developer Sunday, March 25, 2012
  • 14. mmmm... YES, someone did!!! • Connect • Express.js <- yes, I heard about this one • Railways.js <- this is rails style right? • Geddy.js • Tower.js • SocketStream (websockets) • ... Iván Loire 14 freelance node.js developer Sunday, March 25, 2012
  • 15. express.js • High performance, high class web development for node.js. • Simple, minimalist. - Express is one the most common node.js web frameworks out there. • Sexy ..really fast. - It is simple and minimalist. - If you need anything else, get a module. Express is an extra layer of abstraction on top of Node.js so you can easily create high performance web servers • MVC, session support (in-memory, redis), cookie parsing, middleware, view engines (ejs, jade), etc. Iván Loire 15 freelance node.js developer Sunday, March 25, 2012
  • 16. http://expressjs.com Iván Loire 16 freelance node.js developer Sunday, March 25, 2012
  • 17. In the browser .. • Express.js serves HTML pages or render JSON data as response (faster, lighter) • We need something to actually get the JSON data and render the proper UI in the browser. • We need a view-model with declarative bindings, automatic UI refresh, templating... something like... Iván Loire 17 freelance node.js developer Sunday, March 25, 2012
  • 18. knockout.js • Rich, responsive display with a clean underlying data model. – declarative bindinds <span data-bind=”value: msg”></span> – automatic UI refresh – dependency tracking – templating Iván Loire 18 freelance node.js developer Sunday, March 25, 2012
  • 19. Knockout.js model binding - Declarative binding Iván Loire 19 freelance node.js developer Sunday, March 25, 2012
  • 20. - Define the view-model. - Knockout automatically synchronizes UI when model changes. Iván Loire 20 freelance node.js developer Sunday, March 25, 2012
  • 21. Single Page Interface (SPI) node.js socket.io JSON {msg: ‘hi!’} - Once we have our view model, we just <span data-bind=”value: msg”> need to push and pull data from and to the server (by using HTTP or websockets communication) browser We update the view-model using JSON web server through HTTP or over websockets (faster!) Iván Loire 21 freelance node.js developer Sunday, March 25, 2012
  • 22. Example: directorio.cachirulovalley.com - express.js - knockout.js - redis (db) https://github.com/iloire/cachirulovalleydirectory Iván Loire 22 freelance node.js developer Sunday, March 25, 2012
  • 23. Zombie.js from the website (http://zombie.labnotes.org/): Insanely fast, headless full-stack testing using Node.js hey! Why everything is “INSANELY fast” in this presentation?? Iván Loire 23 freelance node.js developer Sunday, March 25, 2012
  • 24. Zombie.js var Browser = require("zombie"); var assert = require("assert"); This code will: browser = new Browser() // Load the page from localhost browser.visit("http://localhost:3000/", function () { - Create a new instance of zombie browser browser. // Fill email, password and submit form - Open url fill("email", "zombie@underworld.dead"). - Find form elements and fill them fill("password", "eat-the-living"). - Submit form - Read and analyze the response pressButton("Sign Me Up!", function() { // Form submitted, new page loaded. assert.ok(browser.success); assert.equal(browser.text("title"), "Welcome To Brains Depot"); }) }); Iván Loire 24 freelance node.js developer Sunday, March 25, 2012
  • 25. Zombie.js • Tests are meant to be fast (or you won’t run them) – Zombie.js run your tests on parallel. • Zombie.js will trigger the proper client side events and will wait for all your asynchronous code to be executed. – This is good for testing SPI (single page interface) apps Iván Loire 25 freelance node.js developer Sunday, March 25, 2012
  • 26. Similar to zombie.js • Phantom.js: (PhantomJS is a headless WebKit with JavaScript AP) • Selenium: (Unit testing with real browsers) Iván Loire 26 freelance node.js developer Sunday, March 25, 2012
  • 27. Last but not least... • Websockets. • Socket.io. • Real-time apps. Iván Loire 27 freelance node.js developer Sunday, March 25, 2012
  • 28. Websockets • Bi-directional, full duplex over a single tcp socket. • Connection remains open = no tcp handshake • Lightweight protocol = no http headers, 2 byte overhead • Supported on chrome 16, FF 11, IE 10, Opera 10 • Reducing latency from 150 (http) to 50 ms (sockets) Iván Loire 28 freelance node.js developer Sunday, March 25, 2012
  • 29. HTTP overhead (for each request) “hello, my name is Chrome, encoding UTF-8... I would like a web page please.” + + HTTP Headers HTTP Headers TCP handshake (request) (response) Iván Loire 29 freelance node.js developer Sunday, March 25, 2012
  • 30. Websockets - HTTP handshake negotiated only once. - 2 bytes overhead - Bi-directional full duplex channel. data + 2 byte overhead data + 2 byte overhead TCP handshake (just first request) Browser Server Iván Loire 30 freelance node.js developer Sunday, March 25, 2012
  • 31. socket.io • Websockets for the rest of us (even IE!!) • Fallback transports: Websockets is not fully supported in all browsers yet. – websockets Some smart people created socket.io, a library for cross browsing real-time – flash sockets communication – ajax long polling If websockets is available, we will use it. If it is not, it will try fallback transports until – ajax streaming one of them works. – iframe – json polling.. Iván Loire 31 freelance node.js developer Sunday, March 25, 2012
  • 32. Don’t forget a really fast database • open source, high performance, in-memory, key-value data store • support master-slave replication, pub/sub channels. • really fast! don’t tell me... • if (ACID) durability is not needed... INSANELY FAST!! Iván Loire 32 freelance node.js developer Sunday, March 25, 2012
  • 33. node.js / socket.io examples • Math-Race – code: https://github.com/iloire/math-race – demo: http://letsnode.com:8090/ - Simple game that shows the basics of socket.io and how you can create applications that communicate browsers in real time. Iván Loire 33 freelance node.js developer Sunday, March 25, 2012
  • 34. Video: http://www.youtube.com/watch?v=LXbYSJfLUW8 Iván Loire 34 freelance node.js developer Sunday, March 25, 2012
  • 35. node.js / socket.io examples • Socket-piano – Play the piano in remote browsers. – code: https://github.com/iloire/socket-piano Let’s try the demo... Iván Loire 35 freelance node.js developer Sunday, March 25, 2012
  • 36. New generation of low latency mobile web apps SenchaTouch2 + node.js + socket.io Iván Loire 36 freelance node.js developer Sunday, March 25, 2012
  • 37. Video: http://www.youtube.com/watch?v=yyHl4cGOlss Iván Loire 37 freelance node.js developer Sunday, March 25, 2012
  • 38. That’s all folks! Eso es todo amigos! Iván Loire @ivanloire http://iloire.com Iván Loire 38 freelance node.js developer Sunday, March 25, 2012