Your SlideShare is downloading. ×
  • Like
  • Save
Express Presentation
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Express Presentation

  • 2,307 views
Published

Intro to Express and Nodejs

Intro to Express and Nodejs

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,307
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide







































Transcript

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