Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Programming for Chaos

Programming for Chaos

An introduction to Node.js

shapeshed

May 17, 2012
Tweet

More Decks by shapeshed

Other Decks in Technology

Transcript

  1. 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
  2. Don't Believe The Hype <3 <3 ZOMG THE New Railsz

    !!!! Make Startup with Node.js === Profit I AM Node.js I AM HIPSTER!!!
  3. Your are in a large empty room There are exits

    to the left or right. Left or right?
  4. 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”
  5. Xbox Controller Internet 8 million controllers Game Servers Databases Chat

    Servers Voice Servers Load Balancers Message Queues More..
  6. A little language called JavaScript var perception = "Toy browser

    language"; var reality = "The language of the web";
  7. 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/');
  8. Non-blocking var fs = require('fs'); fs.readFile(__dirname + '/example.file', 'utf8', function

    (err, data) { if (err) { return console.log(err); } console.log(data); });
  9. Node.js is a platform for • Network programming • Real-time

    • High data throughput • Many concurrent users (It is one approach to concurrency)
  10. When to use Node.js • Single page applications • Real-time

    games • Network Mashups • Data streaming (file uploads) • JSON APIs
  11. 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!'
  12. 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