The new, new hotness.
Eventful JavaScript on the Server

           @dshaw
About.me/dshaw   Web Application Developer
                 WVU 2006, 2008
                 WVU ACM Treasurer
What’s your avor?   Java
                    Python
                             C / C++ / C#
                             Erlang / Haskell
                    Ruby     JavaScript
JavaScript, really?



•   Learning Javascript used to mean you weren't a
    "serious software developer". Today, not learning
    Javascript means the same thing.
                        - James Governor ( @monkchips )
•   http://twitter.com/monkchips/status/25217409319
The Hype   Hacker News <3’s Node.js
           “Everyone’s talking about it.”
GitHub   Node is the #3 most watched project
         on GitHub ...and moving fast.
Why is Node.js so hot?
Node’s Fast.   Non-blocking event driven architecture.
Your Fast!   Speed from idea to prototype to
             production.
Developer Satisfaction!   Love your code.
                           Love coding.
My Favorite Reason

  • JavaScript on the Client

      • JavaScript on the Server


                  = Fun!
Show Me Some Code!

var http = require('http');

http.createServer(function(req, res) {
  res.writeHead(200,
      {'Content-Type': 'text/plain'});
  res.write('Hello, Node.n');
  res.end();
}).listen(1337);

console.log('Server running on :1337');
“Hello, Node.” demo

http://github.com/Marak/hellonode/
var http = require('http');

 http.createServer(function(req, res) {
   res.writeHead(200,
       {'Content-Type': 'text/plain'});
   res.write('Hello, Node.n');
   res.end();
 }).listen(1337);

 console.log('Server running on :1337');




Essential Node.js                   You probably won’t spend too much time
                                    writing request/response code.
var http = require('http');

 http.createServer(function(req, res) {
   res.writeHead(200,
       {'Content-Type': 'text/plain'});
   res.write('Hello, Node.n');
   res.end();
 }).listen(1337);

 console.log('Server running on :1337');




Essential Node.js                   Don’t cheat yourself.
                                     You need to spend some time though.
Require
 var http = require('http');

 http.createServer(function(req, res) {
   res.writeHead(200,
       {'Content-Type': 'text/plain'});
   res.write('Hello, Node.n');
   res.end();
 }).listen(1337);

 console.log('Server running on :1337');




Node’s Anatomy                      CommonJS Require
                                    Server definition
                                    Talk to yourself
Require
 var http = require('http');

 http.createServer(function(req, res) {
   res.writeHead(200,
       {'Content-Type': 'text/plain'});
   res.write('Hello, Node.n');
   res.end();
 }).listen(1337);                 Server
 console.log('Server running on :1337');




Node’s Anatomy                      CommonJS Require
                                    Server definition
                                    Talk to yourself
Require
 var http = require('http');

 http.createServer(function(req, res) {
   res.writeHead(200,
       {'Content-Type': 'text/plain'});
   res.write('Hello, Node.n');
   res.end();
 }).listen(1337);                 Server
 console.log('Server running on :1337');

                        This is for you.

Node’s Anatomy                      CommonJS Require
                                    Server definition
                                    Talk to yourself
Getting Started

                                              • nodejs.org

                                              • API: nodejs.org/api.html

                                              • github.com/ry/node

                                              • github.com/ry/node/wiki

                                              • Google Group [1]

[1]   http://groups.google.com/group/nodejs   • IRC #node.js on Freenode.
Install from source:

 $   git clone http://github.com/ry/node.git
 $   cd node
 $   ./configure
 $   make
 $   make install




Installing Node.js                             It’s really easy.
                                                  (If you’re on a Mac or Linux.)
                                                     Windows... not so much.
Use the Source

http://github.com/ry/node/
Package MGMT
                                    • Use Node Package Manger
                                      aka NPM.

                                    • Community standardized
                                      on NPM in July 2010 [1].

                                    • Install:
                                      github.com/isaacs/npm

                                    • Discover Packages:
[1]   http://dshaw.me/blSO44
                                      npm.mape.me
Use NPM

http://github.com/isaacs/npm/
The Sound of Music   Express
                     Connect
                                   Websocket-Server
                                   Socket-IO
                     Node-Static   Soda
Express

• Express is a *very complete* web
  framework.
• Simple, elegant routing and templating.


• expressjs.com
• github.com/visionmedia/express
• npm install express
Express
// npm dependency
var express = require('express');

var app = express.createServer();

app.get('/', function(req, res){
    res.send('Hello World');
});
app.get('/user/:id', function(req, res){
    res.send('user ' + req.params.id);
});

app.listen(3000);




  • Follow TJ: github.com/visionmedia
Connect

• Connect provides a robust set of
  middleware for building apps:
  logging, static files, JSON-RPC.
• Need sessions, use Connect.


• github.com/senchalabs/connect
• npm install connect
Web Sockets

• Pure Web Sockets.
• Very efficient. Great API.
• Both draft75 and draft76 protocols.
• github.com/miksago/node-websocket-
  server
• npm install websocket-server
Socket.IO

• Abstracts and extends the Web Socket
  metaphor.
• Everything looks like a Web Socket.
• Supports: Flash, XHR Long Polling,
  XHR Multipart Streaming (Comet)
• socket.io (yes, that’s a url.)
• npm install socket.io
Web Sockets Demos
http://github.com/dshaw/canisocket/

           http://dshaw.no.de
http://github.com/dshaw/socketstuffer
Beware: API Changes   A lot of Node.js code you may find on
                      GitHub is outdated. Node tries to help.
More JavaScript   HTML5
                  Canvas
                                  LocalStorage
                                  Web Workers
                  Drag and Drop   Web Sockets
Questions?




http://github.com/dshaw
The new, new hotness.
Eventful JavaScript on the Server

         Thank you.
 http://github.com/dshaw

Node.js - The New, New Hotness

  • 1.
    The new, newhotness. Eventful JavaScript on the Server @dshaw
  • 2.
    About.me/dshaw Web Application Developer WVU 2006, 2008 WVU ACM Treasurer
  • 3.
    What’s your avor? Java Python C / C++ / C# Erlang / Haskell Ruby JavaScript
  • 4.
    JavaScript, really? • Learning Javascript used to mean you weren't a "serious software developer". Today, not learning Javascript means the same thing. - James Governor ( @monkchips ) • http://twitter.com/monkchips/status/25217409319
  • 5.
    The Hype Hacker News <3’s Node.js “Everyone’s talking about it.”
  • 6.
    GitHub Node is the #3 most watched project on GitHub ...and moving fast.
  • 7.
  • 8.
    Node’s Fast. Non-blocking event driven architecture.
  • 9.
    Your Fast! Speed from idea to prototype to production.
  • 10.
    Developer Satisfaction! Love your code. Love coding.
  • 11.
    My Favorite Reason • JavaScript on the Client • JavaScript on the Server = Fun!
  • 12.
    Show Me SomeCode! var http = require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('Hello, Node.n'); res.end(); }).listen(1337); console.log('Server running on :1337');
  • 13.
  • 14.
    var http =require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('Hello, Node.n'); res.end(); }).listen(1337); console.log('Server running on :1337'); Essential Node.js You probably won’t spend too much time writing request/response code.
  • 15.
    var http =require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('Hello, Node.n'); res.end(); }).listen(1337); console.log('Server running on :1337'); Essential Node.js Don’t cheat yourself. You need to spend some time though.
  • 16.
    Require var http= require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('Hello, Node.n'); res.end(); }).listen(1337); console.log('Server running on :1337'); Node’s Anatomy CommonJS Require Server definition Talk to yourself
  • 17.
    Require var http= require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('Hello, Node.n'); res.end(); }).listen(1337); Server console.log('Server running on :1337'); Node’s Anatomy CommonJS Require Server definition Talk to yourself
  • 18.
    Require var http= require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('Hello, Node.n'); res.end(); }).listen(1337); Server console.log('Server running on :1337'); This is for you. Node’s Anatomy CommonJS Require Server definition Talk to yourself
  • 19.
    Getting Started • nodejs.org • API: nodejs.org/api.html • github.com/ry/node • github.com/ry/node/wiki • Google Group [1] [1] http://groups.google.com/group/nodejs • IRC #node.js on Freenode.
  • 20.
    Install from source: $ git clone http://github.com/ry/node.git $ cd node $ ./configure $ make $ make install Installing Node.js It’s really easy. (If you’re on a Mac or Linux.) Windows... not so much.
  • 21.
  • 22.
    Package MGMT • Use Node Package Manger aka NPM. • Community standardized on NPM in July 2010 [1]. • Install: github.com/isaacs/npm • Discover Packages: [1] http://dshaw.me/blSO44 npm.mape.me
  • 23.
  • 24.
    The Sound ofMusic Express Connect Websocket-Server Socket-IO Node-Static Soda
  • 25.
    Express • Express isa *very complete* web framework. • Simple, elegant routing and templating. • expressjs.com • github.com/visionmedia/express • npm install express
  • 26.
    Express // npm dependency varexpress = require('express'); var app = express.createServer(); app.get('/', function(req, res){ res.send('Hello World'); }); app.get('/user/:id', function(req, res){ res.send('user ' + req.params.id); }); app.listen(3000); • Follow TJ: github.com/visionmedia
  • 27.
    Connect • Connect providesa robust set of middleware for building apps: logging, static files, JSON-RPC. • Need sessions, use Connect. • github.com/senchalabs/connect • npm install connect
  • 28.
    Web Sockets • PureWeb Sockets. • Very efficient. Great API. • Both draft75 and draft76 protocols. • github.com/miksago/node-websocket- server • npm install websocket-server
  • 29.
    Socket.IO • Abstracts andextends the Web Socket metaphor. • Everything looks like a Web Socket. • Supports: Flash, XHR Long Polling, XHR Multipart Streaming (Comet) • socket.io (yes, that’s a url.) • npm install socket.io
  • 30.
    Web Sockets Demos http://github.com/dshaw/canisocket/ http://dshaw.no.de http://github.com/dshaw/socketstuffer
  • 31.
    Beware: API Changes A lot of Node.js code you may find on GitHub is outdated. Node tries to help.
  • 32.
    More JavaScript HTML5 Canvas LocalStorage Web Workers Drag and Drop Web Sockets
  • 33.
  • 34.
    The new, newhotness. Eventful JavaScript on the Server Thank you. http://github.com/dshaw