Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Drupal & Node.js: Push your site

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →
typhonius
October 02, 2012

Drupal & Node.js: Push your site

A presentation I gave to DrupalACT which talked about how to push your Drupal site by integration with Node.js

typhonius

October 02, 2012

Transcript

14 slides
  1. http://adammalone.net | http://drupal.org/user/1295980 Node.js – more detail • Single Process

    o Great for simplicity o Must be careful not to block the main event loop • Multiple threads generated • Event Loop
  2. http://adammalone.net | http://drupal.org/user/1295980 node.js Webserver http://nodejs.adammalone.net:13337/ var http = require('http');

    http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Nice and Simple node.js webserver!\n'); }) .listen(13337); console.log('Server running at http://127.0.0.1:1337/');
  3. http://adammalone.net | http://drupal.org/user/1295980 PHP vs Node.js • Assume I run

    Reuters/AP • Necessity for speed in breaking news • Examples are useful!
  4. http://adammalone.net | http://drupal.org/user/1295980 project/nodejs • 5 Main hooks/functions o hook_nodejs_handlers_info

    o hook_nodejs_user_channels o nodejs_send_content_channel_token & nodejs_send_content_channel_message o nodejs_enqueue_message
  5. http://adammalone.net | http://drupal.org/user/1295980 Simplicity $commands[] = ajax_command_before('#main-wrapper', $output); $message =

    (object) array( 'channel' => 'chat_nodejs_auth', 'commands' => $commands, 'callback' => 'nodejsExtras', ); nodejs_enqueue_message($message); (function ($) { Drupal.Nodejs.callbacks.nodejsExtras = { callback: function (message) { Drupal.nodejs_ajax.runCommands(message); } }; }(jQuery));
  6. http://adammalone.net | http://drupal.org/user/1295980 Extending • Drupal o Nodejs chat module

    o Nodejs comments o Users online block o Breaking News o Heartbeat o File Downloads o Your module here • Node o mymodule.server.js o Forever o Many others to hook into
  7. http://adammalone.net | http://drupal.org/user/1295980 Why Not? • Node.js isn’t for everything

    • Do not use for CPU bound operations • Callback spaghetti • Lots of rage online

More Decks by typhonius

Other Decks in Technology