Slide 1

Slide 1 text

Node.js Programming for Chaos

Slide 2

Slide 2 text

Who is this bloke? London-based Ruby and JavaScript developer at pebble {code} Currently authoring Sam's Teach Yourself Node.js in 24 Hours. @shapeshed in the usual places

Slide 3

Slide 3 text

Don't Believe The Hype <3 <3 ZOMG THE New Railsz !!!! Make Startup with Node.js === Profit I AM Node.js I AM HIPSTER!!!

Slide 4

Slide 4 text

Let's Chat! http://192.168.3.1

Slide 5

Slide 5 text

The Web Started Simple HTML Browsers http://

Slide 6

Slide 6 text

Then Became Dynamic cDatabases c Scripting Languages

Slide 7

Slide 7 text

It is different now

Slide 8

Slide 8 text

I'm easily excited

Slide 9

Slide 9 text

I'm cheap Galaxy Apollo £30 (refurb) ● Clients are capable ● Clients can be servers

Slide 10

Slide 10 text

Learning from gaming 10 PRINT "HELLO LONDON WEB!" 20 GOTO 10

Slide 11

Slide 11 text

Your are in a large empty room There are exits to the left or right. Left or right?

Slide 12

Slide 12 text

Input / Output Logic Left Princess!

Slide 13

Slide 13 text

This is predictable ● Map scenarios ● Write Code ● Easy!

Slide 14

Slide 14 text

We even write tests for this Scenario: Player Turns Right Given I am asked to turn left or right When I choose to turn right 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”

Slide 15

Slide 15 text

Stop playing with yourself More difficult

Slide 16

Slide 16 text

Atari Joystick Joystick Output Logic Input(s)

Slide 17

Slide 17 text

Xbox Controller Internet 8 million controllers Game Servers Databases Chat Servers Voice Servers Load Balancers Message Queues More..

Slide 18

Slide 18 text

A little language called JavaScript var perception = "Toy browser language"; var reality = "The language of the web";

Slide 19

Slide 19 text

Browser wars V8 JavaScript Engine ● Super fast ● Highly performant ● Open source

Slide 20

Slide 20 text

A love-child is born 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/');

Slide 21

Slide 21 text

Why JavaScript? Callbacks $("p").hide(1000); alert("This paragraph is hidden"); $("p").hide(1000, function(){ alert("This paragraph is hidden"); });

Slide 22

Slide 22 text

Why JavaScript? The Event Loop ● Single Threaded ● Return fast ● Don't Block

Slide 23

Slide 23 text

Blocking var fs = require('fs'); var data = fs.readFileSync(__dirname + '/example.file','utf8'); console.log(data);

Slide 24

Slide 24 text

Non-blocking var fs = require('fs'); fs.readFile(__dirname + '/example.file', 'utf8', function (err, data) { if (err) { return console.log(err); } console.log(data); });

Slide 25

Slide 25 text

You talk a lot. Show me something!

Slide 26

Slide 26 text

Node.js is a platform for ● Network programming ● Real-time ● High data throughput ● Many concurrent users (It is one approach to concurrency)

Slide 27

Slide 27 text

When to use Node.js ● Single page applications ● Real-time games ● Network Mashups ● Data streaming (file uploads) ● JSON APIs

Slide 28

Slide 28 text

When not to use Node.js ● CPU intensive applications ● CRUD apps on relational databases ● Simple HTML sites ● Just because 'IT IS SO HOT RIGHT NOW!'

Slide 29

Slide 29 text

Where next? ● Express ● https://github.com/visionmedia/express ● Socket.IO ● http://socket.io/ ● dnode ● https://github.com/substack/dnode ● UK Training ● http://leftlogic.com/training#node

Slide 30

Slide 30 text

Thanks! @shapeshed Slides: http://bit.ly/J9Qvbh