SlideShare a Scribd company logo
1 of 55
JavaScript
                            IN THE CLOUD




                                           Mostafa Eweda
                                      eSpace Technologies
                                          10 January, 2013
Saturday, February 2, 13
Program


                     •     Javascript, 1995 to 2013
                     •     Building Cloud9
                     •     Demo




Saturday, February 2, 13
Javascript

                     •     Livescript
                     •     Netscape 2.0
                     •     Not like Java
                     •     More like Scheme




Saturday, February 2, 13
JS had to "look like Java" only
                   less so, [it had to] be
                 Java's dumb kid brother.



Saturday, February 2, 13
XMLHttpRequest


Saturday, February 2, 13
Saturday, February 2, 13
Saturday, February 2, 13
DOM


                     •     Never meant to be scripted
                     •     Direct mapping of C structures
                     •     Incovenient API




Saturday, February 2, 13
Saturday, February 2, 13
Saturday, February 2, 13
Saturday, February 2, 13
Saturday, February 2, 13
Java vs. Javascript




     Let’s confess:
     JavaScript is already the language of the Web
Saturday, February 2, 13
People started to care

                     •     VMs got faster
                           •   And embeddable!
                     •     EcmaScript 5
                     •     JSConf

                  So, JavaScript is a very simple, but often
                  misunderstood language.
Saturday, February 2, 13
Node.js is a NOT another web
          framework. I promise !
Saturday, February 2, 13
Google’s V8 engine
                           as an executable!




Saturday, February 2, 13
LibUV

Saturday, February 2, 13
Asynchronous is cool!




Saturday, February 2, 13
I hate
                           asynchronous!




Saturday, February 2, 13
Normal C++ IO




Saturday, February 2, 13
LibUV C++ IO




Saturday, February 2, 13
Saturday, February 2, 13
Javascript                 LibUV




          Node.js is a platform for building fast,
          scalable network applications.
Saturday, February 2, 13
Javascript bindings to LibUV

                           Standard libraries in JS

                             JS executed in V8


Saturday, February 2, 13
LibUV
                           Not exclusive



Saturday, February 2, 13
Read File in Ruby
       file = File.new("readfile.rb", "r")
       while (line = file.gets)
         # Do something with line
       end
       file.close


                           Read File in Node
  fs.readFile('readfile.js', function (err, buffer){
    if (err) throw err;
    // File is read and we're done.
  });

Saturday, February 2, 13
browser.js


                             db.js


                            server.js

Saturday, February 2, 13
Normal C++ IO
    • Node.js is fast by design.
    • Never blocking on I/O means less
             threads.




Saturday, February 2, 13
Program

 Async.parallel([
   function loadData(next) {
      db.loadData(next);
   },
   function readFile(next) {
     fs.readFile(fName, next);
   ], function done(err, items) {
      if (err) throw err;
      // Do something with items
 });




                           https://github.com/caolan/async
Saturday, February 2, 13
Program
 var user;
 Async.series([
   function loadUser(next) {
      db.getUser(user_id, function(err, u){
          user = u;
          next(err);
      });
   },
   function findItems(next) {
     var sql = "SELECT * FROM store WHERE
 type=?";
      db.query(sql, user.type, next);
   ], function done(err, items) {
      if (err) throw err;
      // Do something with items
 });




Saturday, February 2, 13
Program
               Mix to do complex stuff like:




                           https://github.com/caolan/async
Saturday, February 2, 13
Program


                     •     Javascript, 1995 to 2013
                     •     Building Cloud9
                     •     Demo




Saturday, February 2, 13
Normal developers




Saturday, February 2, 13
JavaScript Developer




Saturday, February 2, 13
is to



           as              is to



Saturday, February 2, 13
You really need HELP



                                    Text




Saturday, February 2, 13
You really need HELP



                                    Text




Saturday, February 2, 13
You really need HELP



                                    Text

           undeclared variable




Saturday, February 2, 13
You really need HELP



                                      Text

           undeclared variable

                                  Iterating using undeclared variable
                                                                        Did you mean “length”?




Saturday, February 2, 13
You really need HELP



                                      Text

           undeclared variable

                                  Iterating using undeclared variable
                                                                        Did you mean “length”?




Saturday, February 2, 13
You really need HELP



                                                            Text

           undeclared variable

                                                        Iterating using undeclared variable
                                                                                                Did you mean “length”?
                                                                                              function created in loop
                            Warning: you are in an anonymous inner function with its own “this” pointer




Saturday, February 2, 13
Saturday, February 2, 13
Debugging




Saturday, February 2, 13
(Smart!) Code completion




Saturday, February 2, 13
Free Linux VM!
Saturday, February 2, 13
Real terminal
Saturday, February 2, 13
Collaboration




Saturday, February 2, 13
Create

                           Deploy
                                                  Run/Debug



                              Share            Test




Saturday, February 2, 13
Program


                     •     Javascript, 1995 to 2012
                     •     Building Cloud9
                     •     Demo




Saturday, February 2, 13
Node.js simple server

            var http = require('http');

      http.createServer(function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end('Hello world');
      }).listen(3000);




Saturday, February 2, 13
Node.js real web app
                            express / connect
          $ npm install -g express
    $     express --sessions --css stylus --ejs jade
    $     cd myapp
    $     npm install
    $     node app.js

    app.get('/hello.txt', function(req, res){
      res.send('Hello World');
    });
    app.listen(3000);
    console.log('Listening on port 3000');


    $ node app

                           http://expressjs.com/
Saturday, February 2, 13
Node.js real web app
                                    Socket.IO 100% JS
          Realtime apps made possible blurring the
          differences between browser transport mechanisms.

    $ npm install socket.io

                           Server                                    Client
   var io = require('socket.io');                    <script src="/socket.io/socket.io.js"></script>
   // attached to the express app                    <script>
   // or runs standalone on port 80                    var socket = io.connect('http://localhost');
   io = io.listen(app || 80);
                                                       socket.on('message', function (msg) {
   io.sockets.on('connection', function (socket) {       console.log(msg);
     socket.on('message', function (msg) {               socket.send({ info: 'trash' });
       console.log(msg);                               });
     });                                             </script>
   });


                                      http://socket.io
Saturday, February 2, 13
Future (Architect)
          • A simple yet powerful plugin system for
                  large-scale Node.js applications
            •       Dependency Injection for JavaScript
                    Managing > ~100K LOC of JS
                    JS: Dynamically typed - Singly threaded



                                http://github.com/c9/architect
Saturday, February 2, 13
Wrap-Up

               • Node.js is brilliant for modern web apps
               • If you do realtime app that is meant to be scalable,
                      you should probably consider Node.js & Socket.io

               • Scale your code base: http://github.com/c9/architect
                      for your application.

               • Check out c9.io for a serious online IDE.

Saturday, February 2, 13
Text

                           http://c9.io


                                                Mostafa Eweda
                                      github.com/mostafaeweda
                                               @mostafaeweda

Saturday, February 2, 13

More Related Content

Similar to Javascript in the cloud

Testing Drupal with Ghosts and Gherkin
Testing Drupal  with Ghosts and GherkinTesting Drupal  with Ghosts and Gherkin
Testing Drupal with Ghosts and GherkinPhase2
 
Invokedynamic: Tales from the Trenches
Invokedynamic: Tales from the TrenchesInvokedynamic: Tales from the Trenches
Invokedynamic: Tales from the TrenchesCharles Nutter
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 MinutesCharles Nutter
 
The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]
The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]
The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]Jason Rhodes
 
The WordPress Hacker's Guide to the \Galaxy() [@Baltimore PHP]
The WordPress Hacker's Guide to the \Galaxy() [@Baltimore PHP]The WordPress Hacker's Guide to the \Galaxy() [@Baltimore PHP]
The WordPress Hacker's Guide to the \Galaxy() [@Baltimore PHP]Jason Rhodes
 
Puppet @ Nedap
Puppet @ NedapPuppet @ Nedap
Puppet @ NedapPuppet
 
GitHub Notable OSS Project
GitHub  Notable OSS ProjectGitHub  Notable OSS Project
GitHub Notable OSS Projectroumia
 
Designing Puppet: Roles/Profiles Pattern
Designing Puppet: Roles/Profiles PatternDesigning Puppet: Roles/Profiles Pattern
Designing Puppet: Roles/Profiles PatternPuppet
 
Welcome to the Symfony2 World - FOSDEM 2013
 Welcome to the Symfony2 World - FOSDEM 2013 Welcome to the Symfony2 World - FOSDEM 2013
Welcome to the Symfony2 World - FOSDEM 2013Lukas Smith
 
RailsConf 2013: RubyMotion
RailsConf 2013: RubyMotionRailsConf 2013: RubyMotion
RailsConf 2013: RubyMotionBrian Sam-Bodden
 
State of Puppet
State of PuppetState of Puppet
State of PuppetPuppet
 
Game Changing Dependency Management
Game Changing Dependency ManagementGame Changing Dependency Management
Game Changing Dependency ManagementJeremy Kendall
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBHiro Asari
 
Writing Reusable Web Components with jQuery and jQuery UI
Writing Reusable Web Components with jQuery and jQuery UIWriting Reusable Web Components with jQuery and jQuery UI
Writing Reusable Web Components with jQuery and jQuery UIYnon Perek
 
Bitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRubyBitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRubyBrian Sam-Bodden
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming IntroductionAnthony Brown
 
MongoDB For C++ Developers
MongoDB For C++ DevelopersMongoDB For C++ Developers
MongoDB For C++ DevelopersYnon Perek
 

Similar to Javascript in the cloud (20)

Play 2 pip
Play 2 pipPlay 2 pip
Play 2 pip
 
Testing Drupal with Ghosts and Gherkin
Testing Drupal  with Ghosts and GherkinTesting Drupal  with Ghosts and Gherkin
Testing Drupal with Ghosts and Gherkin
 
Invokedynamic: Tales from the Trenches
Invokedynamic: Tales from the TrenchesInvokedynamic: Tales from the Trenches
Invokedynamic: Tales from the Trenches
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 Minutes
 
The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]
The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]
The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]
 
The WordPress Hacker's Guide to the \Galaxy() [@Baltimore PHP]
The WordPress Hacker's Guide to the \Galaxy() [@Baltimore PHP]The WordPress Hacker's Guide to the \Galaxy() [@Baltimore PHP]
The WordPress Hacker's Guide to the \Galaxy() [@Baltimore PHP]
 
Wphackergalaxy
WphackergalaxyWphackergalaxy
Wphackergalaxy
 
Puppet @ Nedap
Puppet @ NedapPuppet @ Nedap
Puppet @ Nedap
 
GitHub Notable OSS Project
GitHub  Notable OSS ProjectGitHub  Notable OSS Project
GitHub Notable OSS Project
 
Designing Puppet: Roles/Profiles Pattern
Designing Puppet: Roles/Profiles PatternDesigning Puppet: Roles/Profiles Pattern
Designing Puppet: Roles/Profiles Pattern
 
Welcome to the Symfony2 World - FOSDEM 2013
 Welcome to the Symfony2 World - FOSDEM 2013 Welcome to the Symfony2 World - FOSDEM 2013
Welcome to the Symfony2 World - FOSDEM 2013
 
RailsConf 2013: RubyMotion
RailsConf 2013: RubyMotionRailsConf 2013: RubyMotion
RailsConf 2013: RubyMotion
 
State of Puppet
State of PuppetState of Puppet
State of Puppet
 
With your bare hands
With your bare handsWith your bare hands
With your bare hands
 
Game Changing Dependency Management
Game Changing Dependency ManagementGame Changing Dependency Management
Game Changing Dependency Management
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
Writing Reusable Web Components with jQuery and jQuery UI
Writing Reusable Web Components with jQuery and jQuery UIWriting Reusable Web Components with jQuery and jQuery UI
Writing Reusable Web Components with jQuery and jQuery UI
 
Bitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRubyBitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRuby
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming Introduction
 
MongoDB For C++ Developers
MongoDB For C++ DevelopersMongoDB For C++ Developers
MongoDB For C++ Developers
 

Recently uploaded

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Recently uploaded (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Javascript in the cloud

  • 1. JavaScript IN THE CLOUD Mostafa Eweda eSpace Technologies 10 January, 2013 Saturday, February 2, 13
  • 2. Program • Javascript, 1995 to 2013 • Building Cloud9 • Demo Saturday, February 2, 13
  • 3. Javascript • Livescript • Netscape 2.0 • Not like Java • More like Scheme Saturday, February 2, 13
  • 4. JS had to "look like Java" only less so, [it had to] be Java's dumb kid brother. Saturday, February 2, 13
  • 8. DOM • Never meant to be scripted • Direct mapping of C structures • Incovenient API Saturday, February 2, 13
  • 13. Java vs. Javascript Let’s confess: JavaScript is already the language of the Web Saturday, February 2, 13
  • 14. People started to care • VMs got faster • And embeddable! • EcmaScript 5 • JSConf So, JavaScript is a very simple, but often misunderstood language. Saturday, February 2, 13
  • 15. Node.js is a NOT another web framework. I promise ! Saturday, February 2, 13
  • 16. Google’s V8 engine as an executable! Saturday, February 2, 13
  • 19. I hate asynchronous! Saturday, February 2, 13
  • 20. Normal C++ IO Saturday, February 2, 13
  • 21. LibUV C++ IO Saturday, February 2, 13
  • 23. Javascript LibUV Node.js is a platform for building fast, scalable network applications. Saturday, February 2, 13
  • 24. Javascript bindings to LibUV Standard libraries in JS JS executed in V8 Saturday, February 2, 13
  • 25. LibUV Not exclusive Saturday, February 2, 13
  • 26. Read File in Ruby file = File.new("readfile.rb", "r") while (line = file.gets) # Do something with line end file.close Read File in Node fs.readFile('readfile.js', function (err, buffer){ if (err) throw err; // File is read and we're done. }); Saturday, February 2, 13
  • 27. browser.js db.js server.js Saturday, February 2, 13
  • 28. Normal C++ IO • Node.js is fast by design. • Never blocking on I/O means less threads. Saturday, February 2, 13
  • 29. Program Async.parallel([ function loadData(next) { db.loadData(next); }, function readFile(next) { fs.readFile(fName, next); ], function done(err, items) { if (err) throw err; // Do something with items }); https://github.com/caolan/async Saturday, February 2, 13
  • 30. Program var user; Async.series([ function loadUser(next) { db.getUser(user_id, function(err, u){ user = u; next(err); }); }, function findItems(next) { var sql = "SELECT * FROM store WHERE type=?"; db.query(sql, user.type, next); ], function done(err, items) { if (err) throw err; // Do something with items }); Saturday, February 2, 13
  • 31. Program Mix to do complex stuff like: https://github.com/caolan/async Saturday, February 2, 13
  • 32. Program • Javascript, 1995 to 2013 • Building Cloud9 • Demo Saturday, February 2, 13
  • 35. is to as is to Saturday, February 2, 13
  • 36. You really need HELP Text Saturday, February 2, 13
  • 37. You really need HELP Text Saturday, February 2, 13
  • 38. You really need HELP Text undeclared variable Saturday, February 2, 13
  • 39. You really need HELP Text undeclared variable Iterating using undeclared variable Did you mean “length”? Saturday, February 2, 13
  • 40. You really need HELP Text undeclared variable Iterating using undeclared variable Did you mean “length”? Saturday, February 2, 13
  • 41. You really need HELP Text undeclared variable Iterating using undeclared variable Did you mean “length”? function created in loop Warning: you are in an anonymous inner function with its own “this” pointer Saturday, February 2, 13
  • 45. Free Linux VM! Saturday, February 2, 13
  • 48. Create Deploy Run/Debug Share Test Saturday, February 2, 13
  • 49. Program • Javascript, 1995 to 2012 • Building Cloud9 • Demo Saturday, February 2, 13
  • 50. Node.js simple server var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello world'); }).listen(3000); Saturday, February 2, 13
  • 51. Node.js real web app express / connect $ npm install -g express $ express --sessions --css stylus --ejs jade $ cd myapp $ npm install $ node app.js app.get('/hello.txt', function(req, res){ res.send('Hello World'); }); app.listen(3000); console.log('Listening on port 3000'); $ node app http://expressjs.com/ Saturday, February 2, 13
  • 52. Node.js real web app Socket.IO 100% JS Realtime apps made possible blurring the differences between browser transport mechanisms. $ npm install socket.io Server Client var io = require('socket.io'); <script src="/socket.io/socket.io.js"></script> // attached to the express app <script> // or runs standalone on port 80 var socket = io.connect('http://localhost'); io = io.listen(app || 80); socket.on('message', function (msg) { io.sockets.on('connection', function (socket) { console.log(msg); socket.on('message', function (msg) { socket.send({ info: 'trash' }); console.log(msg); }); }); </script> }); http://socket.io Saturday, February 2, 13
  • 53. Future (Architect) • A simple yet powerful plugin system for large-scale Node.js applications • Dependency Injection for JavaScript Managing > ~100K LOC of JS JS: Dynamically typed - Singly threaded http://github.com/c9/architect Saturday, February 2, 13
  • 54. Wrap-Up • Node.js is brilliant for modern web apps • If you do realtime app that is meant to be scalable, you should probably consider Node.js & Socket.io • Scale your code base: http://github.com/c9/architect for your application. • Check out c9.io for a serious online IDE. Saturday, February 2, 13
  • 55. Text http://c9.io Mostafa Eweda github.com/mostafaeweda @mostafaeweda Saturday, February 2, 13