Bring	 real-time	 interactivity	 to	 Drupal	 with	 Node.js




       Howard Tyson, senior developer, Zivtech
     Kieran Lal, technical director, enterprise sales
Upcoming	
  Webinars
•   Drupal	
  in	
  the	
  Trenches:	
  Solving	
  Real	
  World	
  Problems
•   Five	
  websites	
  you	
  can	
  launch	
  on	
  Dev	
  Cloud	
  without	
  Coding
•   Selecting	
  the	
  Right	
  Solution	
  to	
  Build	
  your	
  Online	
  
    Developer	
  Community
•   Easy	
  Drupal	
  Hosting	
  Lifecycle
•   From	
  PSD	
  to	
  Drupal	
  Theme
•   Four	
  Open	
  Source	
  Drupal	
  Applications	
  for	
  Higher	
  Ed


             http://acquia.com/resources/webinars
Upcoming	
  Node.js	
  Webinars


•   Lessons	
  learned	
  integrating	
  Drupal	
  with	
  Node.js	
  and	
  
    MongoDB	
  powered	
  Web	
  Services
 • Lior	
  Kesos,	
  Swifto,	
  founder	
  Linnovate
 • November	
  9th,	
  2011




            http://acquia.com/resources/webinars
Howard	
  Tyson


•   Howard	
  Tyson,	
  Senior	
  Developer	
  at	
  Zivtech	
  
•   Developing	
  Drupal	
  powered	
  websites	
  since	
  2006.	
  	
  
•   Howard	
  contributes	
  to	
  Drupal	
  and	
  co-­‐maintains	
  the	
  
    Nodejs	
  module,	
  Version	
  Control	
  API	
  among	
  others.
•   Version	
  control	
  powers	
  Git	
  repository	
  on	
  Drupal.org	
  which	
  
    has	
  added	
  6000	
  more	
  developers	
  since	
  Jan,	
  2011
Node.js & Drupal
  Drupal in realtime via Node.js
Who
Who am I?
Howard Tyson


• Drupal.org, twitter, IRC: tizzo
• Senior Developer at Zivtech
• Drupal & systems architect, trainer
Zivtech
• Drupal experts
• Open source enthusiasts (node.js,
  Alfresco, Zend, Python, etc).

• Excellent web/mobile design team
• Offer public and private trainings
  focused on turning smart people
  into excellent developers
What
What is Node.js everyone is talking about,
                 anyway?
Node.js

• Javascript on the server
• Based on Google’s V8 engine
• Event driven
• Asynchronous I/O performed by
 libraries
Architecture
  JavaScript                       C/C++




                your code



           node standard library


    node bindings provided by modules
            (socket, http, etc)


               thread pool
Architecture
• A single process runs the main
  event loop and maintains all
  connections

• Tasks are performed
  asynchronously by workers in a
  thread pool managed by a library
  leaving the main event loop free to
  handle other requests
Node.js hello
       world



• Writing a web server was never so
  easy!
Why
We already have Apache, why is this helpful?
Why we care about
    realtime?
• Users expect more and more (they
  see it on Facebook, Twitter, Google,
  etc. every day)

• Great for mobile
• Bridge the native app gap
A Use Case
• Dignio
• A service for
  improving life for
  patience needing
  additional care but
  not assisted living

• Realtime webapp for
  call center
  employees, patients
Apache’s
     Shortcomings
• One thread (usually
  one process) per
  connection

• Memory heavy
  processes (for
  Drupal especially)

• Persistent and
  concurrent
  connections are
Node.js is good
        for...
• Concurrency!
  • Asynchronous I/O
  • Low overhead for
    open connections

• Light weight servers
• Networking
  applications
Node.js is good
       for...
• Backend workers or serving clients
• Node.js has a vibrant community
  writing extensions (often you just
  need to write some glue, sound
  familiar?)

• Wherever Drupal’s power comes at
  too high a price
How
How do we use node.js with Drupal?
Integarting with
      node.js
• Write your own node.js server
 • if you know javascript, it’s not so
    hard!

• Use drupal’s node.js module for
  realtime communications
The Node.js
       module
• The node.js module on Drupal.org
• http://drupal.org/project/nodejs
• Focused on realtime updates for
  Drupal

 • Provides a node.js server and a
   Drupal module that integrates
   with it
Realtime?

• Until now, when a client opens a
  page they don’t see updates until
  the next time they refresh the page

• Our module can push content to
  someone while they view the page
Authentication
                       4.3. Node.js sends a
                          Drupal returns
                       listauth token to
                            of channels for
                             the user
                              Drupal


    2. Connection
 5. Node.js notifies                       1. Normal Drupal
    requested by
 client that auth is                          Page Load
socket.io using auth
       successful                         (with auth token)
         token
Subsequent pages


      2. Node.js
   remembers the        1. Normal Drupal
    authenticated           Page Load
token, authenticating   (with auth token)
 the user without a
    need to query
     Drupal again
Client requests Drupal page




                       Drupal sends down HTML with JS token




              Client sends auth
              token to Node.js
                                                     Node.js verifies
                                                    token with Drupal



                                                                        Apache
     Client                                           Drupal sends
                                                       appropriate      / Nginx
               Node.js notifies                       channels for the
                 the client of                            user
               successful auth
                                   Node.js

                 Subsequent
               connections do
                not hit Drupal




Web browser              Node.js Server                           Apache Server
Where
Where can my code hook in to leverage
              Node.js?
PHP
JavaScript
Add a user to a
   channel
Message only the
    channel
When
Are we getting new features?
What’s coming

• Version 1.0 is right around the
  corner

• we’re on beta5
• Chatroom is undergoing a refactor
  to rely on a push capable backend
  (like node.js)
New Features

• Content channels (recently landed)
 • Views integration
 • Generic entity updating
 • Your module here...
Call to action!
• We need:
 • Contributors!
 • Documentation writers!
 • Testers!
• http://drupal.org/project/nodejs
• http://drupal.org/project/chatroom
Demo
Let’s see it in action!
Questions
•   For	
  more	
  information	
  visit:	
  	
  http://www.acquia.com
•   Follow	
  us:	
  	
  http://www.twitter.com/acquia
•   Contact	
  us:	
  	
  sales@acquia.com	
  or	
  888.9.ACQUIA
•   Howard	
  Tyson	
  howard@howardtyson.com
•   Kieran	
  Lal,	
  kieran@acquia.com,	
  	
  415-­‐992-­‐8124
•   follow:	
  amazonk
           Today’s	
  webinar	
  recording	
  will	
  be	
  posted	
  to:
     http://acquia.com/resources/recorded_webinars

Bringing Interactivity to Your Drupal Site with Node.js Integration

  • 1.
    Bring real-time interactivity to Drupal with Node.js Howard Tyson, senior developer, Zivtech Kieran Lal, technical director, enterprise sales
  • 2.
    Upcoming  Webinars • Drupal  in  the  Trenches:  Solving  Real  World  Problems • Five  websites  you  can  launch  on  Dev  Cloud  without  Coding • Selecting  the  Right  Solution  to  Build  your  Online   Developer  Community • Easy  Drupal  Hosting  Lifecycle • From  PSD  to  Drupal  Theme • Four  Open  Source  Drupal  Applications  for  Higher  Ed http://acquia.com/resources/webinars
  • 3.
    Upcoming  Node.js  Webinars • Lessons  learned  integrating  Drupal  with  Node.js  and   MongoDB  powered  Web  Services • Lior  Kesos,  Swifto,  founder  Linnovate • November  9th,  2011 http://acquia.com/resources/webinars
  • 4.
    Howard  Tyson • Howard  Tyson,  Senior  Developer  at  Zivtech   • Developing  Drupal  powered  websites  since  2006.     • Howard  contributes  to  Drupal  and  co-­‐maintains  the   Nodejs  module,  Version  Control  API  among  others. • Version  control  powers  Git  repository  on  Drupal.org  which   has  added  6000  more  developers  since  Jan,  2011
  • 6.
    Node.js & Drupal Drupal in realtime via Node.js
  • 7.
  • 8.
    Howard Tyson • Drupal.org,twitter, IRC: tizzo • Senior Developer at Zivtech • Drupal & systems architect, trainer
  • 9.
    Zivtech • Drupal experts •Open source enthusiasts (node.js, Alfresco, Zend, Python, etc). • Excellent web/mobile design team • Offer public and private trainings focused on turning smart people into excellent developers
  • 10.
    What What is Node.jseveryone is talking about, anyway?
  • 11.
    Node.js • Javascript onthe server • Based on Google’s V8 engine • Event driven • Asynchronous I/O performed by libraries
  • 12.
    Architecture JavaScript C/C++ your code node standard library node bindings provided by modules (socket, http, etc) thread pool
  • 13.
    Architecture • A singleprocess runs the main event loop and maintains all connections • Tasks are performed asynchronously by workers in a thread pool managed by a library leaving the main event loop free to handle other requests
  • 14.
    Node.js hello world • Writing a web server was never so easy!
  • 15.
    Why We already haveApache, why is this helpful?
  • 16.
    Why we careabout realtime? • Users expect more and more (they see it on Facebook, Twitter, Google, etc. every day) • Great for mobile • Bridge the native app gap
  • 17.
    A Use Case •Dignio • A service for improving life for patience needing additional care but not assisted living • Realtime webapp for call center employees, patients
  • 18.
    Apache’s Shortcomings • One thread (usually one process) per connection • Memory heavy processes (for Drupal especially) • Persistent and concurrent connections are
  • 19.
    Node.js is good for... • Concurrency! • Asynchronous I/O • Low overhead for open connections • Light weight servers • Networking applications
  • 20.
    Node.js is good for... • Backend workers or serving clients • Node.js has a vibrant community writing extensions (often you just need to write some glue, sound familiar?) • Wherever Drupal’s power comes at too high a price
  • 21.
    How How do weuse node.js with Drupal?
  • 22.
    Integarting with node.js • Write your own node.js server • if you know javascript, it’s not so hard! • Use drupal’s node.js module for realtime communications
  • 23.
    The Node.js module • The node.js module on Drupal.org • http://drupal.org/project/nodejs • Focused on realtime updates for Drupal • Provides a node.js server and a Drupal module that integrates with it
  • 24.
    Realtime? • Until now,when a client opens a page they don’t see updates until the next time they refresh the page • Our module can push content to someone while they view the page
  • 25.
    Authentication 4.3. Node.js sends a Drupal returns listauth token to of channels for the user Drupal 2. Connection 5. Node.js notifies 1. Normal Drupal requested by client that auth is Page Load socket.io using auth successful (with auth token) token
  • 26.
    Subsequent pages 2. Node.js remembers the 1. Normal Drupal authenticated Page Load token, authenticating (with auth token) the user without a need to query Drupal again
  • 27.
    Client requests Drupalpage Drupal sends down HTML with JS token Client sends auth token to Node.js Node.js verifies token with Drupal Apache Client Drupal sends appropriate / Nginx Node.js notifies channels for the the client of user successful auth Node.js Subsequent connections do not hit Drupal Web browser Node.js Server Apache Server
  • 28.
    Where Where can mycode hook in to leverage Node.js?
  • 29.
  • 30.
  • 31.
    Add a userto a channel
  • 32.
  • 33.
    When Are we gettingnew features?
  • 34.
    What’s coming • Version1.0 is right around the corner • we’re on beta5 • Chatroom is undergoing a refactor to rely on a push capable backend (like node.js)
  • 35.
    New Features • Contentchannels (recently landed) • Views integration • Generic entity updating • Your module here...
  • 36.
    Call to action! •We need: • Contributors! • Documentation writers! • Testers! • http://drupal.org/project/nodejs • http://drupal.org/project/chatroom
  • 37.
  • 38.
    Questions • For  more  information  visit:    http://www.acquia.com • Follow  us:    http://www.twitter.com/acquia • Contact  us:    sales@acquia.com  or  888.9.ACQUIA • Howard  Tyson  howard@howardtyson.com • Kieran  Lal,  kieran@acquia.com,    415-­‐992-­‐8124 • follow:  amazonk Today’s  webinar  recording  will  be  posted  to: http://acquia.com/resources/recorded_webinars