Skip to content

Instantly share code, notes, and snippets.

@shapeshed
Last active December 22, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shapeshed/6387661 to your computer and use it in GitHub Desktop.
Save shapeshed/6387661 to your computer and use it in GitHub Desktop.
Hackference Talk

Embracing Chaos with JavaScript

George Ornbo @shapeshed

Hackference, Birmingham 30th August 2013

A brief history

  • HTML born
  • Databases and scripting languages
  • APIs
  • Ajax
  • Web Standards
  • JavaScript

Status quo

  • Everything is networked
  • Everything is connected all the time
  • Everyone has superpowers in their pockets
  • More wearable (and embeddable?) tech to come
  • We have an amazing platform to hack on

But there are still limitations

  • Browsers
  • Databases
  • File Systems
  • Networks

Flip to games

  • PRINT 10 'YOU ARE IN A ROOM'
  • Chess
  • Street Fighter
  • MMORPG
  • Total mania

What tools do we have to respond to this?

So how do we make sense of this?

  • Events
  • An example from the browser
    $('p').hide('slow');
    alert("The paragraph is now hidden");

    $('p').hide('slow', function() {
      alert("The paragraph is now hidden");
    });
  • An example on the server
    var http = require('http');

    http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello Hackference!\n');
    }).listen(3000, "127.0.0.1");

Node.js is one approach

  • JavaScript API into C++ bindings to V8
  • Created by Ryan Dahl
  • V8 is Chrome's JavaScript Engine
  • Small core, big userland
  • UNIX philosophy of doing one thing well

What can you hack on with node?

  • Software
    • Quick HTML Prototypes
    • REST APIs
    • Realtime
    • Data-streaming
  • Hardware
    • Arduinos
    • Quadcopters
    • Serial Ports

npm - node's second best feature

  • Package manager
  • npm install foo
  • npm publish
  • For client-side too (with bower)

Using node for JS tooling

  • Grunt
  • JSHint
  • grunt-* tools
  • Testing
  • Building

Streams - node's best feature

  • Washing your car. Bucket or hose.
  • Using data when it is ready
  • API stabilising
  • Most things in node are a stream
    var fs = require('fs');

    var stream = fs.ReadStream('enormous.txt');

    stream.setEncoding('utf8');

    stream.on('data', function(chunk) {
      console.log('read some data')
    });

    stream.on('close', function () {
      console.log('we are done')
    });
  • Like UNIX you can pipe
    var http = require('http'),
        fs = require('fs');

    http.createServer(function(request, response) {
      var mp3 = 'birdie-song.mp3';
      var stat = fs.statSync(mp3);

      response.writeHead(200, {
        'Content-Type': 'audio/mpeg',
        'Content-Length': stat.size
      });

      var readableStream = fs.createReadStream(mp3);
      readableStream.pipe(response);

    }).listen(3000);

Some things to know

  • The server and the application are one process
  • Self-hosting can be tricky
  • Heroku and Nodejitsu offer free hosting
  • There isn't a Rails equivalent in node.js
  • Callbacks
  • CoffeeScript

Who is using node?

  • eBay
  • Yahoo
  • Voxer
  • LinkedIn

Where can I find out more?

  • Start with Express
  • IRC, Mailing lists, blog posts
  • Books
  • But most of all hack!

Over to Andrew.

  • Andrew likes bunnies
  • Andrew makes a mean chocoloate brownie
  • Andrew organises LNUG and The Great British Node Conf
  • He has drones!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment