JavaScript on theserverNode.Js
Logical Architecture RIARepresentation of data,           Subset of data  interact with user            needed for the vie...
Old Fashioned Setup   XHTML                  browser                           http            PHP             PHP        ...
Disadvantages Old FashionedSetup Mix of HTML and PHP Heavy HTTP traffic
Classical Setup   HTML5           JSON                          browser     JavaScript/jQuery                           ht...
Disadvantages Classical Setup Still need to learn different languages with a  different development model PHP is on its ...
Don’t put your money on PHPHacker News Survey (2012)   Job Offerings Dice.com (2012)Python (3,054)              Java 17,59...
Modern Setup  HTML5                    JSON                                  browser      JavaScript/jQuery               ...
Advantages Modern Setup Only one development language: JavaScript Not only HTTP, WebSockets to the rescue
Disadvantages Modern Setup OO in JavaScript is doable but PHP syntax  resembles Java/C# more Node hosting is harder to g...
Node
Node.js in one slide Built On Chromes JavaScript V8 Engine Node.js is a general-purpose JavaScript runtime  with a host ...
Node Architecture   http://www.gliffy.com/publish/2752090/
Node Modules   Connect: Extensible HTTP server framework   Socket.IO: WebSockets and Realtime   Mocha: BDD/TDD Test Run...
Node: Connectvar connect = require("connect”);connect().   use(connect.      static(__dirname + "/../client")).        lis...
Node: Socket.IOvar io = require("socket.io").listen(1337);io.sockets.on("connection", function (socket) {   socket.on("sav...
Node: Socket.IO           Browser           initiates                 Server                initiates
WebSockets vs HTTP                                           Use case A: 1,000 clients                                    ...
StockQuote using XmlHttpRequestBrowserinitiates
StockQuote using WebSockets?                                           Server                                          ini...
Node: Write your own module                  Use one or more other modules,                       external or your ownvar ...
Mongo
Mongo in one slide   Stores data as bson (binary JSON)   Console uses JavaScript and json   3rd party GUI tools   Data...
Mongo Architecture
Mongoose
Mongoose in one slide “Mongoose is the 10gen-supported ODM for  Node.js. It has a thriving open source community  and inc...
Mongoose example  http://mongoosejs.com/index.html
Upcoming SlideShare
Loading in …5
×

JavaScript on the server - Node.js

4,422 views

Published on

Lecture for CRIA-WT about JavaScript on the server. Explains why we prefer Node.js over PHP and shows the architecture, modules and a small demo application on https://github.com/rodmidde/cria-wt-demo/tree/master/NODE/SimpleMVC.

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
4,422
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

JavaScript on the server - Node.js

  1. 1. JavaScript on theserverNode.Js
  2. 2. Logical Architecture RIARepresentation of data, Subset of data interact with user needed for the view Handles events and calls services Interface to the back-end Classes, Business or Application Logic Something QL- like Raw data, relational or not
  3. 3. Old Fashioned Setup XHTML browser http PHP PHP server MySQLi PHP MySQL
  4. 4. Disadvantages Old FashionedSetup Mix of HTML and PHP Heavy HTTP traffic
  5. 5. Classical Setup HTML5 JSON browser JavaScript/jQuery http PHP PDO POPO server MySQL
  6. 6. Disadvantages Classical Setup Still need to learn different languages with a different development model PHP is on its return
  7. 7. Don’t put your money on PHPHacker News Survey (2012) Job Offerings Dice.com (2012)Python (3,054) Java 17,599 (+8.96%)Ruby (1,723) XML 10,780 (+11.70%)JavaScript (1,415) JavaScript 10,738 (+11.64%)C (970) HTML 9,587 (-1.53%)C# (829)PHP (666) C# 9,293 (+17.04%)Java (551) C++ 6,439 (+7.55%)C++ (529) AJAX 5,142 (+15.81%)Haskell (519) Perl 5,107 (+3.21%) Programming Book sales (2012)Clojure (459) PHP 3,717 (+23%) 1. JavaCoffeeScript (362) Python 3,456 (+32.87%) 2. JavaScriptObjective C (326) Ruby 2,141 (+39.03%) 3. C#Lisp (322) HTML5 2,035 (+276.85%) 4. Objective CPerl (311)Scala (233) Flash 1,261 (+95.2%) 5. C++Scheme (190) Silverlight 865 (-11.91%) 6. PHPOther (188) COBOL 656 (-10.75%) 7. VBAErlang (162) Assembler 209 (-1.42%) 8. PythonLua (145) PowerBuilder 126 (-18.71%) 9. SQLSQL (101) FORTRAN 45 (-33.82%) 10. ActionScript http://readwrite.com/2012/06/05/5-ways-to-tell-which-programming-lanugages-are-most-popular
  8. 8. Modern Setup HTML5 JSON browser JavaScript/jQuery websockets http JavaScript Mongoose JSON server MongoDB
  9. 9. Advantages Modern Setup Only one development language: JavaScript Not only HTTP, WebSockets to the rescue
  10. 10. Disadvantages Modern Setup OO in JavaScript is doable but PHP syntax resembles Java/C# more Node hosting is harder to get than PHP hosting Node’s learning curve is more sheer compared to PHP
  11. 11. Node
  12. 12. Node.js in one slide Built On Chromes JavaScript V8 Engine Node.js is a general-purpose JavaScript runtime with a host of powerful libraries -- one of which happens to provide an HTTP/HTTPS server implementation Node.js Is Object-Oriented Evented (Async) I/O Package Management with npm
  13. 13. Node Architecture http://www.gliffy.com/publish/2752090/
  14. 14. Node Modules Connect: Extensible HTTP server framework Socket.IO: WebSockets and Realtime Mocha: BDD/TDD Test Runner Express: Web Framework build on Connect JSLint, JSHint: JavaScript Quality Tools Jasmine: BDD/TDD Test Runner Mongoose: ODM for MongoDB
  15. 15. Node: Connectvar connect = require("connect”);connect(). use(connect. static(__dirname + "/../client")). listen(8000);
  16. 16. Node: Socket.IOvar io = require("socket.io").listen(1337);io.sockets.on("connection", function (socket) { socket.on("saveNewPlayer", function (data) { console.log(data); socket.emit("saveReady"); });});
  17. 17. Node: Socket.IO Browser initiates Server initiates
  18. 18. WebSockets vs HTTP Use case A: 1,000 clients Use case B: 10,000 clients Use case C: 100,000 clients http://www.websocket.org/quantum.html
  19. 19. StockQuote using XmlHttpRequestBrowserinitiates
  20. 20. StockQuote using WebSockets? Server initiates Too bad Yahoo does not support WebSockets yet 
  21. 21. Node: Write your own module Use one or more other modules, external or your ownvar Player = require(../model/Player.js); Simple constructorfunction EntityManager() { this.saveNewPlayer = function(name, club,playerNumber, saveReadyFunction) { // do something cool here }} Let other modules know what we can do for themmodule.exports = EntityManager;
  22. 22. Mongo
  23. 23. Mongo in one slide Stores data as bson (binary JSON) Console uses JavaScript and json 3rd party GUI tools Database runs as an exe or Windows service Memory mapped so really needs 64bit OS User group on Google Groups [busy] Sharding for fast access and huge storage files.meetup.com/2313351/Mongo.pptx
  24. 24. Mongo Architecture
  25. 25. Mongoose
  26. 26. Mongoose in one slide “Mongoose is the 10gen-supported ODM for Node.js. It has a thriving open source community and includes advanced schema-based features such as async validation, casting, object life- cycle management, pseudo-joins, and rich query builder support.”
  27. 27. Mongoose example http://mongoosejs.com/index.html

×