Express Presentation

2,689 views

Published on

Intro to Express and Nodejs

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,689
On SlideShare
0
From Embeds
0
Number of Embeds
25
Actions
Shares
0
Downloads
0
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide







































  • Express Presentation

    1. 1. EXPRESS web framework for node Aaron Heckmann aaronheckmann@gmail.com Area 15 http://twitter.com/aaronheckmann April 15 2010
    2. 2. HISTORY (abridged)
    3. 3. GMAIL
    4. 4. CHROME
    5. 5. V8
    6. 6. RYAN DAHL
    7. 7. SERVERS
    8. 8. NGINX
    9. 9. EVENT LOOP
    10. 10. JAVASCRIPT
    11. 11. SPEED
    12. 12. V8
    13. 13. evented I/O for V8 javascript
    14. 14. ASYNC I/O <?php // I block! $data = file_get_contents($file) // do stuff with $data ?>
    15. 15. ASYNC I/O <?php // I block! $data = file_get_contents($file) // do stuff with $data ?> jQuery.ajax({ success: function(data) { // do something with data } })
    16. 16. 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 })
    17. 17. 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
    18. 18. FAMILIAR • addListener() • removeListener() • setTimeout() • setInterval()
    19. 19. LOW LEVEL • HTTP / TCP / DNS • file system • child processes • event emitters • and streams, oh my!
    20. 20. • lots • lots • more
    21. 21. EXPRESS • simple install • built on node • async rendering • plugable
    22. 22. SIMPLE INSTALL $ git clone git://github.com/visionmedia/express.git $ cd express && git submodule update --init or $ kiwi -v install express
    23. 23. 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
    24. 24. ASYNC RENDERING get('/', function(){ return '<!doctype html><html><head><title>...' })
    25. 25. ASYNC RENDERING get('/', function() { var self = this // => Request })
    26. 26. ASYNC RENDERING get('/', function() { var self = this db.get(someUserId, function(err, user) { if (err) return self.error(err); }) })
    27. 27. 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 } }) }) })
    28. 28. #wrap .welcome %p= “Hello ” + firstname + “!” <div id=“wrap”> <div class=“welcome”> <p>Hello Aaron!</p> </div> </div>
    29. 29. .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; }
    30. 30. PLUGABLE
    31. 31. PLUGABLE • View, Cache, Redirect, etc (defaults) • Cookie, Session, Flash, Logger, Static, etc (optional) • 3rd party session persistence (MongoDB, Redis) • Async!
    32. 32. PLUGABLE var Logger = require('express/plugins/logger').Logger use(Logger, {format: 'combined'})
    33. 33. MOAR • partials & flash messaging • custom error pages (500, 404) • http (async curl) • uploads • custom environment configurations • ES5 (v8)
    34. 34. 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

    ×