Slide 1

Slide 1 text

Node.js an introduction to Humans,Networks and Chaos Monday, 13 February 12

Slide 2

Slide 2 text

Don’t believe Hype The Monday, 13 February 12

Slide 3

Slide 3 text

Chat! Let’s Monday, 13 February 12

Slide 4

Slide 4 text

>10 PRINT "HELLO LWSG!"; >20 GOTO 10 Monday, 13 February 12

Slide 5

Slide 5 text

Room You are in a with 2 exits Left or right? Monday, 13 February 12

Slide 6

Slide 6 text

Input / Output Logic Left You found the Princess! Monday, 13 February 12

Slide 7

Slide 7 text

Map scenarios Write code Easy! Monday, 13 February 12

Slide 8

Slide 8 text

Scenario: Player Turns Left Given I am asked to turn left or right When I choose to turn left Then I should see “Eaten by a dragon” Scenario: Player Turns Right Given I am asked to turn left or right When I choose to turn left Then I should see “You found the Princess” Monday, 13 February 12

Slide 9

Slide 9 text

Stop playing with yourself. Monday, 13 February 12

Slide 10

Slide 10 text

Stop playing with yourself. More difficult. Monday, 13 February 12

Slide 11

Slide 11 text

Atari Joystick Joystick Input(s) Logic Output Monday, 13 February 12

Slide 12

Slide 12 text

8 way joystick 2 buttons 2 players Monday, 13 February 12

Slide 13

Slide 13 text

8 way joystick 2 buttons 2 players Unpredictable Humans Monday, 13 February 12

Slide 14

Slide 14 text

Xbox Controller Internet Map scenarios for this Game Servers Databases Chat Servers Voice Servers Load balancers Message queues .. more 8 million controllers Monday, 13 February 12

Slide 15

Slide 15 text

Concurrency Fork Synchronous Threads Single-thread Events Monday, 13 February 12

Slide 16

Slide 16 text

Concurrency This is hard Node.js is a response Monday, 13 February 12

Slide 17

Slide 17 text

Events Browsers Humans It works. JavaScript Monday, 13 February 12

Slide 18

Slide 18 text

Event loop Single threaded Don’t block Return fast Monday, 13 February 12

Slide 19

Slide 19 text

thread One Monday, 13 February 12

Slide 20

Slide 20 text

thread One INSANE? Are YOU And JavaScript? Monday, 13 February 12

Slide 21

Slide 21 text

Performance http://blog.webfaction.com/a-little-holiday-present Monday, 13 February 12

Slide 22

Slide 22 text

Memory http://blog.webfaction.com/a-little-holiday-present Monday, 13 February 12

Slide 23

Slide 23 text

Web is changing (again) The Monday, 13 February 12

Slide 24

Slide 24 text

Network EVERYTHING Phones Tablets TVs Monday, 13 February 12

Slide 25

Slide 25 text

Toasters Bus stops Cars Billboards Fridges Network EVERYTHING APIs Monday, 13 February 12

Slide 26

Slide 26 text

Turn left or right? Server Browser Monday, 13 February 12

Slide 27

Slide 27 text

Still ok? Server Browser DB Server Monday, 13 February 12

Slide 28

Slide 28 text

Still ok? Browser Server App Servers Databases Chat Servers Voice Servers Load balancers Message queues 3rd party APIs ..more Unlimited things Millions of users. Phones, Tablets, TVs Billboards, Fridges more.. Monday, 13 February 12

Slide 29

Slide 29 text

Chaos Data flow Networks Monday, 13 February 12

Slide 30

Slide 30 text

Chaos Data flow Humans Networks Monday, 13 February 12

Slide 31

Slide 31 text

Push Real-time Networked High concurrency Monday, 13 February 12

Slide 32

Slide 32 text

I/O event-driven Non-blocking Monday, 13 February 12

Slide 33

Slide 33 text

I/O event-driven Non-blocking What? Monday, 13 February 12

Slide 34

Slide 34 text

With Javascript. @hij1nx That is all. Network programming. Monday, 13 February 12

Slide 35

Slide 35 text

V8 Brains FAST Networks Performance Monday, 13 February 12

Slide 36

Slide 36 text

JavaScript EVENTED JSON Browsers Mis- Well understood Monday, 13 February 12

Slide 37

Slide 37 text

var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, "127.0.0.1"); console.log('Server running at http:// 127.0.0.1:1337/'); HelloWorld Monday, 13 February 12

Slide 38

Slide 38 text

HelloWorld var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, "127.0.0.1"); console.log('Server running at http:// 127.0.0.1:1337/'); Monday, 13 February 12

Slide 39

Slide 39 text

Callbacks Do something when you FINISH Monday, 13 February 12

Slide 40

Slide 40 text

$("p").hide(1000); alert("The paragraph is now hidden"); $("p").hide(1000,function(){ alert("The paragraph is now hidden"); }); Callbacks in jQuery Monday, 13 February 12

Slide 41

Slide 41 text

var urls = db.query("select * from urls"); urls.each(function () { var page = http.get(url); save(page); }); db.query("select * from urls", function (urls) { urls.each(function(url) { http.get(url, function (page) { save(page); }); }); }); Jacek Becela http://www.slideshare.net/jacekbecela/introduction-to-nodejs Monday, 13 February 12

Slide 42

Slide 42 text

var urls = db.query("select * from urls"); urls.each(function () { var page = http.get(url); save(page); }); db.query("select * from urls", function (urls) { urls.each(function(url) { http.get(url, function (page) { save(page); }); }); }); http://www.slideshare.net/jacekbecela/introduction-to-nodejs Blocking Blocking Blocking Monday, 13 February 12

Slide 43

Slide 43 text

var urls = db.query("select * from urls"); urls.each(function () { var page = http.get(url); save(page); }); db.query("select * from urls", function (urls) { urls.each(function(url) { http.get(url, function (page) { save(page); }); }); }); http://www.slideshare.net/jacekbecela/introduction-to-nodejs Blocking Blocking Blocking Callbacks Monday, 13 February 12

Slide 44

Slide 44 text

Head Hurts Show Me something FUN Monday, 13 February 12

Slide 45

Slide 45 text

Forget order Embrace Random Events Monday, 13 February 12

Slide 46

Slide 46 text

Where next? Express (gateway drug) - http://expressjs.com Socket.io (fast high) - http://socket.io/ dnode (blows mind) - https://github.com/substack/dnode UK Training http://leftlogic.com/training#node Monday, 13 February 12

Slide 47

Slide 47 text

Thanks! @shapeshed Slides: bit.ly/A8azQ7 Monday, 13 February 12