node.js 101



@ChrisMatthieu

#dcc12

What is Node.JS

  • Server Side Javascript
  • Uses Chrome V8 JS Engine
  • Non-Blocking I/O
  • Streams
  • Active Community

Who iS using node.js

  • eBay
  • Yahoo
  • LinkedIn
  • Microsoft
  • Walmart
  • Yammer
  • Voxer
  • ...

Node.js is webscale





Node.js is not another
web framework




NODE.JS IS
SERVER SIDE JAVASCRIPT


...or CoffeeScript

Node.js is perfect as...

  • Web server
  • TCP server
  • Proxy server
  • Streaming server
  • Awesome robot controller
  • Command line application
  • Realtime dashboards
  • ANYTHING THAT DEALS 
    WITH HIGH I/O

WHY NODE.JS?

  • Non-blocking I/O (FAST!)
  • Based on Chrome's V8 JS Engine (FAST!)
  • 15,000+ Modules
  • Active Community (IRC, Mailing lists, Twitter, GH)
  • Mac, Linux, Windows (all 1st class citizens)
  • 1 language for Frontend & Backend
  • Javascript is the language of the web

    http://nodejs.org




some basic
examples

Hello world

Create hello-world.js
| console.log('Hello World');

On the command line run
$ node hello-world.js

You should see
Hello World

Basic http server


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/');


* I can achieve 10,000+ requests/sec with 100 concurrent connections without a sweat!


Some people use the 

core HTTP module to 

build their web apps, 

most use a framework

like Express

Express JS


var express = require('express');
var app = express();

app.get('/', function(req, res){
  res.send('hello world');
});

app.listen(3000);




what is non-blocking i/o
and why should i care?

Blocking i/o


270ms = Sum(user,activities,leaderboard)

non-blocking i/o


150ms = MAX(user,activities,leaderboard)

meet the node package manager
otherwise known as Npm


It's how you harness the 
#awesomeness of the 
Node.JS community!

Using npm

To install a new module
$ npm install <module>

To find a module in the NPM directory
$ npm search <search string>

To list the modules in current project
$ npm list

To see module details
$ npm info <module>

NPM and package.json

{

    "name": "my appname"

  , "version": "0.0.1"

  , "node": "0.8.1"

  , "dependencies": {

      "express": "*"

  }

  , "devDependencies": {

      "jade": "*"

  }

  , "engines": {

      "node": "0.8.x",

      "npm": "1.1.x"

  }

}

npm is #awesomesauce


Visit 

http://npmjs.org

for more details and to browse
the current directory of modules

My favorite modules

  • express
  • request
  • mongojs
  • everyauth
  • ntwitter
  • socket.io
  • async
  • redis
  • xmlson
  • jade

node.js streaming?!

  • Video uploads with concurrent encoding
  • Handling with large without memory constraints
  • Transforming XML/JSON on the fly
  • Zipping and Unzipping files on the fly

REaltime web!

Web Sockets!
- Socket.io
- Socks.js
- ws

Frameworks   
- Meteor
- Derby
- SocketStream

Node-CopterS!



hack

the

Planet!




Questions?

contact me at clmatthi@bechtel.com

givePlug(){
              console.log("we're hiring node.js developers!");
}