Slide 1

Slide 1 text

SenchaLabs Connect & Express High Performance Servers written in JavaScript Monday, September 20, 2010

Slide 2

Slide 2 text

Why we need non-blocking Polling is too slow and inefficient. Live interaction requires the server to push data. In order to push data, the connections need to be persistent. The server needs to handle thousands of persistent connections. Threads aren’t going to scale. Monday, September 20, 2010

Slide 3

Slide 3 text

Why we need JavaScript You already use it in the client. It’s already event based and not threaded. It’s actually a good language if used right. Lambdas, closures, garbage collection. V8 is a really fast VM Monday, September 20, 2010

Slide 4

Slide 4 text

Node's goal is to provide an easy way to build performant network programs. This is in contrast to today's more common concurrency model where OS threads are employed. Node programs are written in JavaScript. Monday, September 20, 2010

Slide 5

Slide 5 text

Hello World in Node.js // Load the http module var http = require('http'); // Setup a request handler for a simple HTTP server. // Listen on port 3000 http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/ plain'}); res.end('Hello World\n'); }).listen(3000, "127.0.0.1"); // Print a pretty message to the terminal console.log('Server running at http:// 127.0.0.1:3000/'); Monday, September 20, 2010

Slide 6

Slide 6 text

Hello World in Connect // Load the connect module Connect = require('connect'); // Setup a simple Connect server server = Connect.createServer( function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World\n'); } ); // Export the server so Spark can run it module.exports = server; Monday, September 20, 2010

Slide 7

Slide 7 text

Stacking in Middleware Node provides very low level APIs There is no cookie handling or parsing. There is no session support built-in. There is no routing built-in. There is no static file serving. Connect makes this easy! Monday, September 20, 2010

Slide 8

Slide 8 text

Bundled Modules Static File Server Apache Style Logs Body Decoder Cookie Decoder Session Provider Request Router Fancy Error Handler Cache Manifest Conditional Get Inline Gzipping Virtual Host Router Sass/Less Compiler Monday, September 20, 2010

Slide 9

Slide 9 text

Connect with Layers Connect.createServer( Connect.logger(), Connect.conditionalGet(), Connect.cache(), Connect.gzip(), Connect.staticProvider("public"), Connect.bodyDecoder(), Connect.cookieDecoder(), Connect.session(), Connect.router(routes), Connect.errorHandler({showStack: true}) ); Monday, September 20, 2010

Slide 10

Slide 10 text

Express is even easier Connect is a framework maker’s framework. It’s much easier than raw node.js, but still low level. Express is a simple framework for application developers. It’s inspired by Sinatra from the Ruby world. Monday, September 20, 2010

Slide 11

Slide 11 text

Express Example // Create an express app var app = express.createServer(); // Setup a route handler app.get('/', function(req, res){ res.send('Hello World'); }); // Start the HTTP server app.listen(3000); Monday, September 20, 2010

Slide 12

Slide 12 text

DEMO TIME! Monday, September 20, 2010

Slide 13

Slide 13 text

http://senchalabs.github.com/connect http://expressjs.com http://nodejs.org http://raphaeljs.com Links to Projects Used Monday, September 20, 2010