Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Common Node


Published on

Published in: Technology, Design
  • Be the first to comment

  • Be the first to like this

Common Node

  1. 1. Intro to Common Node #camdug 27.08.2011
  2. 2. Why use JavaScript on the server? <ul><li>Language of the browser, widely accessible </li></ul><ul><li>Dynamic language </li></ul><ul><li>Closures and asynchronous programming </li></ul><ul><li>Diverse, active, growing community </li></ul><ul><li>We are stuck with it for the foreseeable future </li></ul>
  3. 4. Akshell NarwhalJS Wakanda RingoJS
  4. 5. CommonJS modules // math.js exports.add = function(a, b) { return a + b; } // server.js var add = require('math').add; console.log(add(2, 2)); // client.js ???
  5. 6. CommonJS packages // package.json { &quot;name&quot;: &quot;hello&quot;, &quot;version&quot;: &quot;0.1.0&quot;, &quot;description&quot;: &quot;Hello world package&quot;, &quot;keywords&quot;: [&quot;hello&quot;, &quot;world&quot;], &quot;author&quot;: &quot;John Smith <>&quot;, &quot;main&quot;: &quot;./lib/hello.js&quot;, &quot;dependencies&quot;: {&quot;whatever&quot; : &quot;1&quot;}, &quot;engines&quot; : [&quot;v8&quot;, &quot;node&quot;, &quot;rhino&quot;], }
  6. 7. Node.js Event Loop <ul><li>Handle all I/O in one process </li></ul><ul><li>No blocking calls, use callbacks instead </li></ul><ul><li>Less memory used and higher throughput due to fewer context switches </li></ul><ul><li>Use JavaScript closures to capture state </li></ul>
  7. 8. Async vs. Sync function add(callback) { http.get(url1, function(response1) { var part1 =; http.get(url2, function(response2) { var part2 =; callback(part1 + part2); } } }
  8. 9. Async vs. Sync http.get(url1) + http.get(url2)
  9. 10. Interoperability <ul><li>Pure JavaScript CommonJS modules can run in any environment </li></ul><ul><ul><li>Templating, parsing, formatting, encoding </li></ul></ul><ul><li>Anything that does I/O must expose either a synchronous or an asynchronous API </li></ul><ul><ul><li>Dictates the style of interface exposed by higher level packages </li></ul></ul>
  10. 11. Common Node <ul><li>Implements a number of synchronous CommonJS specifications on top of Node </li></ul><ul><ul><li>Binary, IO, Filesystem, JSGI and more </li></ul></ul><ul><li>Uses node-fibers </li></ul><ul><ul><li>Co routine implementation, not a fork or a hack of Node </li></ul></ul><ul><li>Google's Traceur to support latest language features </li></ul><ul><li>Bridges the gap between platforms, sync and async </li></ul><ul><li>Google “ common node ”, watch on GitHub </li></ul>
  11. 13. <ul><li>Thank you! </li></ul><ul><li>Comments? </li></ul><ul><li>@olegpodsechin </li></ul>