• Save
Express Presentation
Upcoming SlideShare
Loading in...5
×
 

Express Presentation

on

  • 2,898 views

Intro to Express and Nodejs

Intro to Express and Nodejs

Statistics

Views

Total Views
2,898
Views on SlideShare
2,874
Embed Views
24

Actions

Likes
4
Downloads
0
Comments
0

3 Embeds 24

http://www.techgig.com 21
http://www.slideshare.net 2
http://coderwall.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Express Presentation Express Presentation Presentation Transcript

  • EXPRESS web framework for node Aaron Heckmann aaronheckmann@gmail.com Area 15 http://twitter.com/aaronheckmann April 15 2010
  • HISTORY (abridged)
  • GMAIL
  • CHROME
  • V8
  • RYAN DAHL
  • SERVERS
  • NGINX
  • EVENT LOOP
  • JAVASCRIPT
  • SPEED
  • V8
  • evented I/O for V8 javascript
  • ASYNC I/O <?php // I block! $data = file_get_contents($file) // do stuff with $data ?>
  • ASYNC I/O <?php // I block! $data = file_get_contents($file) // do stuff with $data ?> jQuery.ajax({ success: function(data) { // do something with data } })
  • ASYNC I/O <?php // I block! $data = file_get_contents($file) // do stuff with $data ?> jQuery.ajax({ success: function(data) { // do something with data } }) // I don’t block! var fs = require('fs') fs.readFile(file, function(err, data) { // i can has data })
  • REQUIRE • Node uses the commonJS module system • returns the exported API of a module // math.js exports.add = function() { var sum = arguments[0]; for (var i=1; i<arguments.length; i++) { sum += arguments[i]; } return sum; }; // app.js var add = require('math').add; add(4, 8, 15, 16, 23, 42); //-> 108
  • FAMILIAR • addListener() • removeListener() • setTimeout() • setInterval()
  • LOW LEVEL • HTTP / TCP / DNS • file system • child processes • event emitters • and streams, oh my!
  • • lots • lots • more
  • EXPRESS • simple install • built on node • async rendering • plugable
  • SIMPLE INSTALL $ git clone git://github.com/visionmedia/express.git $ cd express && git submodule update --init or $ kiwi -v install express
  • BUILT ON NODE // app.js require.paths.unshift('path/to/express/lib') require('express') get('/', function(){ this.redirect('/hello/world') }) get('/hello/world', function(){ return 'Hello World' }) run() $ node app.js Express started at http://localhost:8000/ in development mode
  • ASYNC RENDERING get('/', function(){ return '<!doctype html><html><head><title>...' })
  • ASYNC RENDERING get('/', function() { var self = this // => Request })
  • ASYNC RENDERING get('/', function() { var self = this db.get(someUserId, function(err, user) { if (err) return self.error(err); }) })
  • ASYNC RENDERING get('/', function() { var self = this db.get(someUserId, function(err, user) { if (err) return self.error(err); self.render('home.html.haml', { layout: 'layout-public’, locals: { title: 'intro to express', firstname: user.firstname } }) }) })
  • #wrap .welcome %p= “Hello ” + firstname + “!” <div id=“wrap”> <div class=“welcome”> <p>Hello Aaron!</p> </div> </div>
  • .welcome :margin 5px p :color #2C7C00 :text-shadow 1px 2px 1px #ddd .welcome { margin: 5px; } .welcome p { color: #2C7C00; text-shadow: 1px 2px 1px #ddd; }
  • PLUGABLE
  • PLUGABLE • View, Cache, Redirect, etc (defaults) • Cookie, Session, Flash, Logger, Static, etc (optional) • 3rd party session persistence (MongoDB, Redis) • Async!
  • PLUGABLE var Logger = require('express/plugins/logger').Logger use(Logger, {format: 'combined'})
  • MOAR • partials & flash messaging • custom error pages (500, 404) • http (async curl) • uploads • custom environment configurations • ES5 (v8)
  • THANK YOU • http://expressjs.com/ • http://groups.google.com/group/express-js • http://github.com/visionmedia/express • http://nodejs.org/ • http://groups.google.com/group/nodejs • http://wiki.github.com/ry/node/modules • http://twitter.com/expressjs • http://twitter.com/aaronheckmann