[TW] Node.js

2,820 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,820
On SlideShare
0
From Embeds
0
Number of Embeds
534
Actions
Shares
0
Downloads
15
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • [TW] Node.js

    1. 1. Server Side Programming Using Node.JS Ana-Maria Daneliuc Bogdan GazaTW2011
    2. 2. $whoarewe Students at Faculty of Computer Science ana.daneliuc@info.uaic.ro bogdan.gaza@info.uaic.roTW2011
    3. 3. JavaScriptTW2011
    4. 4. Java is to JavaScript Like ham is to hamsterTW2011
    5. 5. JavaScript • Language of the Internet • Scripting language (interpreted) • Client side - usually run by the browser • Object oriented • Event drivenTW2011
    6. 6. JavaScript • Growing in popularity • Big companies spend a lot of $$$ to improve JavaScript • Probably will become a very popular languageTW2011
    7. 7. JavaScript • Until recent no clear - server side JavaScript console interpreter • Event driven on the server side also • Code sharing • All fast evented network servers were written in C/C++TW2011
    8. 8. Node.JS Server Side JavaScriptTW2011
    9. 9. Node.js • Event driven I/O framework • Build upon V8 engine • Server Side (includes system calls + different modules) • Intended for writing scalable network programs • Written in C/C++ and JavaScriptTW2011
    10. 10. V8TW2011
    11. 11. V8 JavaScript Engine • JavaScript VM used by Google Chrome • Written by one of the leading VM engineers with 20 years of building VMs - Lars Bak • The last VM written by Lars Bak - improved JavaScript 20x times.TW2011
    12. 12. V8 JavaScript Engine • JavaScript to assembler • Improved garbage collector • Independent from Google Chrome • Limitations: No bytecode/No threads/No processesTW2011
    13. 13. Non BlockingTW2011
    14. 14. Blocking puts("Enter your name: "); var name = gets(); puts("Name: " + name);TW2011
    15. 15. Non-Blocking - Node.js way puts("Enter your name: "); gets(function(name){ puts("Name: " + name); });TW2011
    16. 16. Remember Select From the “Retele” Node.js Course aka explain select say about poll/epoll When receiving data (from network / disk / another source) there must be a callback Data is received Data Event Source loop CallBack User FunctionTW2011
    17. 17. Non-blocking vs threadedTW2011
    18. 18. Non-blocking vs threadedTW2011
    19. 19. Node.js - Hello World var http = require(http); http.createServer(function (req, res) { res.writeHead(200, {Content-Type: text/plain}); res.end(Hello Worldn); }).listen(8124, "127.0.0.1"); console.log(Server running at http://127.0.0.1:8124/);TW2011
    20. 20. Why use Node.js?TW2011
    21. 21. Real time web applicationsTW2011
    22. 22. Ajax • Asynchronous JavaScript and XML • Method to load data asynchronously • Uses XMLHttpRequest object (from JS) • Nearly real timeTW2011
    23. 23. Step 1 Loading Web Page ServerTW2011
    24. 24. Step 2 Done Web Page Server Ajax RequestTW2011
    25. 25. Step 3 Done Web Page Server Ajax RequestTW2011
    26. 26. Step 4 Done Web Page Server Ajax RequestTW2011
    27. 27. Step 5 Done Web Page Server Ajax Request For another request goto step 1TW2011
    28. 28. Comet Long-lived HTTP connections Reduce latency Messages are passed from the server to the client PUSHTW2011
    29. 29. Step 1 Loading Web Page ServerTW2011
    30. 30. Step 2 Done Web Page Server Long lived HTTPTW2011
    31. 31. Step 3 Event Done Web Page Server Long lived HTTPTW2011
    32. 32. Step 4 Done Web Page Server Long lived HTTPTW2011
    33. 33. Step 5 Done Web Page Server Long lived HTTPTW2011
    34. 34. Step 6 Done Web Page Server Long lived HTTP For another request goto step 1TW2011
    35. 35. WebSockets • Use TCP sockets from the browser • Update web page 40 times / s • API is work in progress • Not supported by all the modern browsersTW2011
    36. 36. Ajax vs Comet vs WebSockets Ajax Comet WebSocketsTW2011
    37. 37. DEMOTW2011
    38. 38. Q/ATW2011
    39. 39. Thanks!TW2011

    ×