Javascript in the cloud

1,982 views
1,852 views

Published on

Presented in eSpace Tech Talk http://www.espace.com.eg/
& later in BadrIT http://www.badrit.com/

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,982
On SlideShare
0
From Embeds
0
Number of Embeds
379
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Javascript in the cloud

  1. 1. JavaScript IN THE CLOUD Mostafa Eweda eSpace Technologies 10 January, 2013Saturday, February 2, 13
  2. 2. Program • Javascript, 1995 to 2013 • Building Cloud9 • DemoSaturday, February 2, 13
  3. 3. Javascript • Livescript • Netscape 2.0 • Not like Java • More like SchemeSaturday, February 2, 13
  4. 4. JS had to "look like Java" only less so, [it had to] be Javas dumb kid brother.Saturday, February 2, 13
  5. 5. XMLHttpRequestSaturday, February 2, 13
  6. 6. Saturday, February 2, 13
  7. 7. Saturday, February 2, 13
  8. 8. DOM • Never meant to be scripted • Direct mapping of C structures • Incovenient APISaturday, February 2, 13
  9. 9. Saturday, February 2, 13
  10. 10. Saturday, February 2, 13
  11. 11. Saturday, February 2, 13
  12. 12. Saturday, February 2, 13
  13. 13. Java vs. Javascript Let’s confess: JavaScript is already the language of the WebSaturday, February 2, 13
  14. 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. 15. Node.js is a NOT another web framework. I promise !Saturday, February 2, 13
  16. 16. Google’s V8 engine as an executable!Saturday, February 2, 13
  17. 17. LibUVSaturday, February 2, 13
  18. 18. Asynchronous is cool!Saturday, February 2, 13
  19. 19. I hate asynchronous!Saturday, February 2, 13
  20. 20. Normal C++ IOSaturday, February 2, 13
  21. 21. LibUV C++ IOSaturday, February 2, 13
  22. 22. Saturday, February 2, 13
  23. 23. Javascript LibUV Node.js is a platform for building fast, scalable network applications.Saturday, February 2, 13
  24. 24. Javascript bindings to LibUV Standard libraries in JS JS executed in V8Saturday, February 2, 13
  25. 25. LibUV Not exclusiveSaturday, February 2, 13
  26. 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 were done. });Saturday, February 2, 13
  27. 27. browser.js db.js server.jsSaturday, February 2, 13
  28. 28. Normal C++ IO • Node.js is fast by design. • Never blocking on I/O means less threads.Saturday, February 2, 13
  29. 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/asyncSaturday, February 2, 13
  30. 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. 31. Program Mix to do complex stuff like: https://github.com/caolan/asyncSaturday, February 2, 13
  32. 32. Program • Javascript, 1995 to 2013 • Building Cloud9 • DemoSaturday, February 2, 13
  33. 33. Normal developersSaturday, February 2, 13
  34. 34. JavaScript DeveloperSaturday, February 2, 13
  35. 35. is to as is toSaturday, February 2, 13
  36. 36. You really need HELP TextSaturday, February 2, 13
  37. 37. You really need HELP TextSaturday, February 2, 13
  38. 38. You really need HELP Text undeclared variableSaturday, February 2, 13
  39. 39. You really need HELP Text undeclared variable Iterating using undeclared variable Did you mean “length”?Saturday, February 2, 13
  40. 40. You really need HELP Text undeclared variable Iterating using undeclared variable Did you mean “length”?Saturday, February 2, 13
  41. 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” pointerSaturday, February 2, 13
  42. 42. Saturday, February 2, 13
  43. 43. DebuggingSaturday, February 2, 13
  44. 44. (Smart!) Code completionSaturday, February 2, 13
  45. 45. Free Linux VM!Saturday, February 2, 13
  46. 46. Real terminalSaturday, February 2, 13
  47. 47. CollaborationSaturday, February 2, 13
  48. 48. Create Deploy Run/Debug Share TestSaturday, February 2, 13
  49. 49. Program • Javascript, 1995 to 2012 • Building Cloud9 • DemoSaturday, February 2, 13
  50. 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. 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. 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.ioSaturday, February 2, 13
  53. 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/architectSaturday, February 2, 13
  54. 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. 55. Text http://c9.io Mostafa Eweda github.com/mostafaeweda @mostafaewedaSaturday, February 2, 13

×