+ All Categories
Home > Technology > JavaScript on the server - Node.js

JavaScript on the server - Node.js

Date post: 17-Jan-2015
Category:
Upload: rody-middelkoop
View: 3,783 times
Download: 2 times
Share this document with a friend
Description:
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.
Popular Tags:
27
JavaScript on the server Node.Js
Transcript
Page 1: JavaScript on the server - Node.js

JavaScript on the server

Node.Js

Page 2: JavaScript on the server - Node.js

Logical Architecture RIA

Raw data, relational or not

Something QL-like

Classes, Business or Application Logic

Interface to the back-end

Handles events and calls services

Representation of data, interact with user

Subset of data needed for the view

Page 3: JavaScript on the server - Node.js

server

browser

Old Fashioned Setup

MySQL

MySQLi PHP

PHP

XHTML

PHP

http

Page 4: JavaScript on the server - Node.js

Disadvantages Old Fashioned Setup

Mix of HTML and PHP Heavy HTTP traffic

Page 5: JavaScript on the server - Node.js

server

browser

Classical Setup

MySQL

PDO POPO

PHP

HTML5

JavaScript/jQuery

JSON

http

Page 6: JavaScript on the server - Node.js

Disadvantages Classical Setup

Still need to learn different languages with a different development model

PHP is on its return

Page 7: JavaScript on the server - Node.js

Don’t put your money on PHP

Hacker News Survey (2012)Python (3,054)Ruby (1,723)JavaScript (1,415)C (970)C# (829)PHP (666)Java (551)C++ (529)Haskell (519)Clojure (459)CoffeeScript (362)Objective C (326)Lisp (322)Perl (311)Scala (233)Scheme (190)Other (188)Erlang (162)Lua (145)SQL (101)

http://readwrite.com/2012/06/05/5-ways-to-tell-which-programming-lanugages-are-most-popular

Job Offerings Dice.com (2012)Java 17,599 (+8.96%)XML 10,780 (+11.70%)JavaScript 10,738 (+11.64%)HTML 9,587 (-1.53%)C# 9,293 (+17.04%)C++ 6,439 (+7.55%)AJAX 5,142 (+15.81%)Perl 5,107 (+3.21%)PHP 3,717 (+23%)Python 3,456 (+32.87%)Ruby 2,141 (+39.03%)HTML5 2,035 (+276.85%)Flash 1,261 (+95.2%)Silverlight 865 (-11.91%)COBOL 656 (-10.75%)Assembler 209 (-1.42%)PowerBuilder 126 (-18.71%)FORTRAN 45 (-33.82%)

Programming Book sales (2012)1. Java2. JavaScript3. C#4. Objective C5. C++6. PHP7. VBA8. Python9. SQL10. ActionScript

Page 8: JavaScript on the server - Node.js

server

browser

Modern Setup

MongoDB

Mongoose JSON

JavaScript

HTML5

JavaScript/jQuery

JSON

http

websockets

Page 9: JavaScript on the server - Node.js

Advantages Modern Setup

Only one development language: JavaScript

Not only HTTP, WebSockets to the rescue

Page 10: JavaScript on the server - Node.js

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

Page 11: JavaScript on the server - Node.js

Node

Page 12: JavaScript on the server - Node.js

Node.js in one slide

Built On Chrome's 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

Page 13: JavaScript on the server - Node.js

Node Architecture

http://www.gliffy.com/publish/2752090/

Page 14: JavaScript on the server - Node.js

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

Page 15: JavaScript on the server - Node.js

Node: Connect

var connect = require("connect”);connect().

use(connect.static(__dirname +

"/../client")).listen(8000);

Page 16: JavaScript on the server - Node.js

Node: Socket.IO

var io = require("socket.io").listen(1337);io.sockets.on("connection", function (socket) {

socket.on("saveNewPlayer", function (data){

console.log(data);socket.emit("saveReady");

}); });

Page 17: JavaScript on the server - Node.js

Node: Socket.IO

Browser initiates

Serverinitiates

Page 18: JavaScript on the server - Node.js

WebSockets vs HTTP

Use case A: 1,000 clients

Use case C: 100,000 clients

Use case B: 10,000 clients

http://www.websocket.org/quantum.html

Page 19: JavaScript on the server - Node.js

StockQuote using XmlHttpRequest

Browser initiates

Page 20: JavaScript on the server - Node.js

StockQuote using WebSockets?

Serverinitiates

Too bad Yahoo does not support WebSockets yet

Page 21: JavaScript on the server - Node.js

Node: Write your own module

var Player = require('../model/Player.js');

function EntityManager() {this.saveNewPlayer = function(name,

club, playerNumber, saveReadyFunction) {// do something cool here

}}

module.exports = EntityManager;

Use one or more other modules, external or your own

Simple constructor

Let other modules know what we can do for them

Page 22: JavaScript on the server - Node.js

Mongo

Page 23: JavaScript on the server - Node.js

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

Page 24: JavaScript on the server - Node.js

Mongo Architecture

Page 25: JavaScript on the server - Node.js

Mongoose

Page 26: JavaScript on the server - Node.js

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.”

Page 27: JavaScript on the server - Node.js

Mongoose example

http://mongoosejs.com/index.html


Recommended