SlideShare a Scribd company logo
Building your first Node app with Connect & Express Christian Joudrey - @cjoudrey
Getting Started Node.js:  http://nodejs.org/#download npm, a package manager for Node: curl http://npmjs.org/install.sh | sh Use npm to install Connect and Express for Node: npm install connect && npm install express Many more modules at:  http://npm.mape.me/
Hello World in Node.js // Load the http module var  http = require(' http '); // Setup a HTTP server, listen on port 8080 http.createServer(function (req, res) {    res.writeHead(200, {      ' Content-Type ': ' text/plain '    });    res.end(' Hello World '); }).listen(8080, ' 127.0.0.1 ');
Node's HTTP module Very low level. No cookie handling or parsing. No session support built-in. No routing built-in. No static file serving.
Connect makes it easier Static File Server Body Decoder Cookie Decoder Session Provider Request Router Logs Sass/Less Compiler Virtual Host Router
...but, you decide what blocks you want.
Hello World in Connect // Load the connect module var  connect = require(' connect '); // Setup a HTTP server, listen on port 8080 connect.createServer(function (req, res) {    res.writeHead(200, {      ' Content-Type ': ' text/plain '    });    res.end(' Hello World '); }).listen(8080, ' 127.0.0.1 ');
.use() and next() var  connect = require(' connect '); var  s = connect.createServer(); s.use(function (req, res, next) {    // Send to next handler if url not /about    if  (req.url != ' /about ')  return  next();    res.end(' About page '); }); s.use(function (req, res, next) {    res.end(' Default page '); }); s.listen(8080, ' 127.0.0.1 ');
Routing Middleware s.use(connect.router(function(app) {    app.get(' /users ', function(req, res, next) {      res.end(' List users ');    });    app.post(' /users ', function(req, res, next) {      res.end(' Create a new user ');    });    app.get(' /user/:id ', function(req, res, next) {      if (!is_admin(req)) {        return  next( new  Error(' access denied '));      }      res.end(' Edit user  ' + req.params.id);    }); })); s.use(function(err, req, res, next) {    res.end(err.message); });
Full example with Connect var  connect = require(' connect '); var  s = connect.createServer(); s.use(connect.logger()); s.use(connect.favicon(__dirname + ' /static/favicon.ico ')); s.use(connect.static(__dirname + ' /static ')); s.use(connect.cookieParser());  // adds req.cookies s.use(connect.bodyParser());  // adds req.body s.use(connect.router(require(' ./users ')); s.use(connect.router(require(' ./index ')); s.use(function(err, req, res, next) {    res.end(' Internal Server Error '); }); s.listen(8080, ' 127.0.0.1 ');
Express is even easier Connect is easier than raw node.js, but still low level. ...but, it's good for simple RESTful API's ...or to make your own framework. Express is a simple framework inspired by Sinatra (Ruby). It's built on top of Connect.
Hello World in Express var  express = require(' express '); var  app = express.createServer(); app.get(' / ', function(req, res) {    res.send(' hello world '); }); app.listen(8080);
Getting Started with Express Generate skeleton apps: express –help Generate app with sessions and template engine: express --sessions --template ejs hello Generated structure: $ ls hello/ app.js   logs    pids    public    test    views $ ls hello/views/ index.ejs  layout.ejs
Configurations app.configure(function() {    // Global configurations    app.use(express.bodyParser());  // parse incoming data    app.use(express.cookieParser());  // parse cookies    app.use(express.session({ secret: ' your secret ' }); }); app.configure(' development ', function() {    // Development configurations    // i.e. Error handler to print errors and show stack? }); app.configure(' production ', function() {    // Production configurations }); Controlled by:        NODE_ENV=production node app.js
Routing app.get(' /users ', function(req, res) {    // List user }); app.post(' /users ', function(req, res) {    // Create user    // req.body contains POST data }); app.get(' /user/:id ', function(req, res) {    // Edit user    // req.params.id contains value of :id param });
Sanitizing Route Params app.param(' :id ', function(v) {    return  parseInt(v, 10); }); app.get(' /user/:id ', function(req, res) {    res.send(' user id:  ' + req.params.id); });
Even better... var  integer = function(v) {    return  parseInt(v, 10); }; app.param(' :id ', integer); app.get(' /user/:id ', function(req, res) {    res.send(' user id:  ' + req.params.id); });
Route Param Pre-conditions app.get(' /user/:id ', function(req, res) {    var  id = req.params.id;    User.get(id, function(err, user) {      if  (err)  return  next(err);      res.send(' user  ' + user.name);    }); }); app.put(' /user/:id ', function(req, res) {    var  id = req.params.userId;    User.get(id, function(err, user) {      if  (err)  return  next(err);      user.update(req.body);    }); }); Same logic every time there is  :id
Even better... var  loadUser = function(req, res, next) {    var  id = req.params.id;    User.get(id, function(err, user) {      if  (err)  return  next(err);      if  (!user)  return  next( new  Error(' invalid userId '));      req.user = user;      next();    }); }); app.get(' /user/:id ', loadUser, function(req, res) {    res.send(' user  ' + req.user.name); }); app.put(' /user/:id ', loadUser, function(req, res) {    req.user.update(req.body); });
You can stack them... app.put(' /user/:id ', isAdmin, loadUser, function(req, res) {    req.user.update(req.body); }); app.put(' /user/:id ', function(req, res, next) {    // Verify if the current user is an admin    isAdmin(req, res, function(err) {      if  (err)  return  next(err);      loadUser(req, res, function(err, user) {        if  (err)  return  next(err);        req.user.update(req.body);      });    }); }); ...cleaner than...
Views "Built-in" support for : Jade (Haml-like):  http://jade-lang.com/ EJS (Embedded JS):  http://embeddedjs.com/ Support for partials.
Rendering Views app.get(' /user/:id ', loadUser, function(req, res) {    res.render(' user_edit ', {      locals: {        user: req.user,        title: ' Edit User  ' + req.user.username      }    }); });
Other useful functions... app.helpers(Object) Set functions that are available in your views app.dynamicHelpers(Object) Set helpers that require the req and res objects app.error(Function), called when: throw new Error() next(new Error())
Interesting Links Lots of Express examples:  http://bit.ly/ExpressExamples Express Documentation:   http://bit.ly/ExpressDocs Database wrappers and ORMs: Mongoose (MongoDB, ORM-like):  https://github.com/LearnBoost/mongoose Cradle (CouchDB, HTTP wrapper): https://github.com/cloudhead/cradle Couch-ar (CouchDB, Active Record implementation): https://github.com/scottburch/couch-ar
Questions?  :)

More Related Content

PDF
Express node js
Yashprit Singh
 
PDF
All aboard the NodeJS Express
David Boyer
 
PPT
RESTful API In Node Js using Express
Jeetendra singh
 
PPT
Node js presentation
martincabrera
 
KEY
Writing robust Node.js applications
Tom Croucher
 
KEY
Building a real life application in node js
fakedarren
 
PPTX
introduction to node.js
orkaplan
 
PDF
Node.js - A Quick Tour
Felix Geisendörfer
 
Express node js
Yashprit Singh
 
All aboard the NodeJS Express
David Boyer
 
RESTful API In Node Js using Express
Jeetendra singh
 
Node js presentation
martincabrera
 
Writing robust Node.js applications
Tom Croucher
 
Building a real life application in node js
fakedarren
 
introduction to node.js
orkaplan
 
Node.js - A Quick Tour
Felix Geisendörfer
 

What's hot (20)

PDF
Node ppt
Tamil Selvan R S
 
PDF
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
PPTX
Express js
Manav Prasad
 
KEY
Node.js - Best practices
Felix Geisendörfer
 
PDF
NodeJS for Beginner
Apaichon Punopas
 
PPTX
Java script at backend nodejs
Amit Thakkar
 
KEY
A million connections and beyond - Node.js at scale
Tom Croucher
 
PDF
Building servers with Node.js
ConFoo
 
PPTX
Overview of Node JS
Jacob Nelson
 
PDF
Nodejs Explained with Examples
Gabriele Lana
 
PDF
Introduction to Nodejs
Gabriele Lana
 
KEY
NodeJS
.toster
 
PDF
Nodejs in Production
William Bruno Moraes
 
PDF
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
PDF
NodeJS
LinkMe Srl
 
KEY
node.js: Javascript's in your backend
David Padbury
 
PPTX
Intro to Node.js (v1)
Chris Cowan
 
PDF
Node Architecture and Getting Started with Express
jguerrero999
 
KEY
Introduction to node.js
jacekbecela
 
PPTX
Introduction Node.js
Erik van Appeldoorn
 
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
Express js
Manav Prasad
 
Node.js - Best practices
Felix Geisendörfer
 
NodeJS for Beginner
Apaichon Punopas
 
Java script at backend nodejs
Amit Thakkar
 
A million connections and beyond - Node.js at scale
Tom Croucher
 
Building servers with Node.js
ConFoo
 
Overview of Node JS
Jacob Nelson
 
Nodejs Explained with Examples
Gabriele Lana
 
Introduction to Nodejs
Gabriele Lana
 
NodeJS
.toster
 
Nodejs in Production
William Bruno Moraes
 
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
NodeJS
LinkMe Srl
 
node.js: Javascript's in your backend
David Padbury
 
Intro to Node.js (v1)
Chris Cowan
 
Node Architecture and Getting Started with Express
jguerrero999
 
Introduction to node.js
jacekbecela
 
Introduction Node.js
Erik van Appeldoorn
 
Ad

Viewers also liked (12)

PPTX
Node.js Express
Eyal Vardi
 
PPTX
Building Web Apps with Express
Aaron Stannard
 
PPT
The Business Case for Node.js
Joe McCann
 
PPTX
Rest api with node js and express
GirlsInTechnology Nepal
 
PPTX
Express yourself
Yaniv Rodenski
 
PPTX
Node JS Express : Steps to Create Restful Web App
Edureka!
 
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
PDF
How to Customize Multiple Shirt Sizes
Transfer Express
 
PDF
The Enterprise Case for Node.js
NodejsFoundation
 
PPTX
Diving into Node with Express and Mongo
Axilis
 
PDF
Create Restful Web Application With Node.js Express Framework
Edureka!
 
PDF
Node, express & sails
Brian Shannon
 
Node.js Express
Eyal Vardi
 
Building Web Apps with Express
Aaron Stannard
 
The Business Case for Node.js
Joe McCann
 
Rest api with node js and express
GirlsInTechnology Nepal
 
Express yourself
Yaniv Rodenski
 
Node JS Express : Steps to Create Restful Web App
Edureka!
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
How to Customize Multiple Shirt Sizes
Transfer Express
 
The Enterprise Case for Node.js
NodejsFoundation
 
Diving into Node with Express and Mongo
Axilis
 
Create Restful Web Application With Node.js Express Framework
Edureka!
 
Node, express & sails
Brian Shannon
 
Ad

Similar to Building your first Node app with Connect & Express (20)

PPT
Going crazy with Node.JS and CakePHP
Mariano Iglesias
 
PPTX
Express JS
Alok Guha
 
PDF
Nodejs first class
Fin Chen
 
ODP
Summit2011 satellites-robinf-20110605
Robin Fernandes
 
ODP
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Atlassian
 
PDF
Build Web Apps using Node.js
davidchubbs
 
PPTX
express-express-express-express-express-
pransu471shdp
 
PPTX
Nodejs.meetup
Vivian S. Zhang
 
PDF
node.js practical guide to serverside javascript
Eldar Djafarov
 
PDF
express of full stack web development notes
JeneferAlan1
 
ODP
Implementing Comet using PHP
King Foo
 
PDF
DataStax: 0 to App faster with Ruby and NodeJS
DataStax Academy
 
PPT
RingoJS
Oleg Podsechin
 
KEY
How and why i roll my own node.js framework
Ben Lin
 
PDF
Build web application by express
Shawn Meng
 
PDF
Silex Cheat Sheet
Andréia Bohner
 
PDF
Silex Cheat Sheet
Andréia Bohner
 
PPTX
express.js.pptxgghhhhhhnnbvcdssazxvuyiknvc
rani marri
 
PDF
How to quickly make REST APIs with CompoundJS
Frank Rousseau
 
PPT
Services Apps Iand Flex Applications
Sumit Kataria
 
Going crazy with Node.JS and CakePHP
Mariano Iglesias
 
Express JS
Alok Guha
 
Nodejs first class
Fin Chen
 
Summit2011 satellites-robinf-20110605
Robin Fernandes
 
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Atlassian
 
Build Web Apps using Node.js
davidchubbs
 
express-express-express-express-express-
pransu471shdp
 
Nodejs.meetup
Vivian S. Zhang
 
node.js practical guide to serverside javascript
Eldar Djafarov
 
express of full stack web development notes
JeneferAlan1
 
Implementing Comet using PHP
King Foo
 
DataStax: 0 to App faster with Ruby and NodeJS
DataStax Academy
 
How and why i roll my own node.js framework
Ben Lin
 
Build web application by express
Shawn Meng
 
Silex Cheat Sheet
Andréia Bohner
 
Silex Cheat Sheet
Andréia Bohner
 
express.js.pptxgghhhhhhnnbvcdssazxvuyiknvc
rani marri
 
How to quickly make REST APIs with CompoundJS
Frank Rousseau
 
Services Apps Iand Flex Applications
Sumit Kataria
 

Recently uploaded (20)

PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
PDF
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PPTX
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
Doc9.....................................
SofiaCollazos
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 

Building your first Node app with Connect & Express

  • 1. Building your first Node app with Connect & Express Christian Joudrey - @cjoudrey
  • 2. Getting Started Node.js: http://nodejs.org/#download npm, a package manager for Node: curl http://npmjs.org/install.sh | sh Use npm to install Connect and Express for Node: npm install connect && npm install express Many more modules at: http://npm.mape.me/
  • 3. Hello World in Node.js // Load the http module var http = require(' http '); // Setup a HTTP server, listen on port 8080 http.createServer(function (req, res) {    res.writeHead(200, {      ' Content-Type ': ' text/plain '    });    res.end(' Hello World '); }).listen(8080, ' 127.0.0.1 ');
  • 4. Node's HTTP module Very low level. No cookie handling or parsing. No session support built-in. No routing built-in. No static file serving.
  • 5. Connect makes it easier Static File Server Body Decoder Cookie Decoder Session Provider Request Router Logs Sass/Less Compiler Virtual Host Router
  • 6. ...but, you decide what blocks you want.
  • 7. Hello World in Connect // Load the connect module var  connect = require(' connect '); // Setup a HTTP server, listen on port 8080 connect.createServer(function (req, res) {    res.writeHead(200, {      ' Content-Type ': ' text/plain '    });    res.end(' Hello World '); }).listen(8080, ' 127.0.0.1 ');
  • 8. .use() and next() var  connect = require(' connect '); var s = connect.createServer(); s.use(function (req, res, next) {    // Send to next handler if url not /about    if (req.url != ' /about ') return next();    res.end(' About page '); }); s.use(function (req, res, next) {    res.end(' Default page '); }); s.listen(8080, ' 127.0.0.1 ');
  • 9. Routing Middleware s.use(connect.router(function(app) {    app.get(' /users ', function(req, res, next) {      res.end(' List users ');    });    app.post(' /users ', function(req, res, next) {      res.end(' Create a new user ');    });    app.get(' /user/:id ', function(req, res, next) {      if (!is_admin(req)) {        return next( new Error(' access denied '));      }      res.end(' Edit user ' + req.params.id);    }); })); s.use(function(err, req, res, next) {    res.end(err.message); });
  • 10. Full example with Connect var connect = require(' connect '); var s = connect.createServer(); s.use(connect.logger()); s.use(connect.favicon(__dirname + ' /static/favicon.ico ')); s.use(connect.static(__dirname + ' /static ')); s.use(connect.cookieParser()); // adds req.cookies s.use(connect.bodyParser()); // adds req.body s.use(connect.router(require(' ./users ')); s.use(connect.router(require(' ./index ')); s.use(function(err, req, res, next) {    res.end(' Internal Server Error '); }); s.listen(8080, ' 127.0.0.1 ');
  • 11. Express is even easier Connect is easier than raw node.js, but still low level. ...but, it's good for simple RESTful API's ...or to make your own framework. Express is a simple framework inspired by Sinatra (Ruby). It's built on top of Connect.
  • 12. Hello World in Express var  express = require(' express '); var  app = express.createServer(); app.get(' / ', function(req, res) {    res.send(' hello world '); }); app.listen(8080);
  • 13. Getting Started with Express Generate skeleton apps: express –help Generate app with sessions and template engine: express --sessions --template ejs hello Generated structure: $ ls hello/ app.js   logs    pids    public    test    views $ ls hello/views/ index.ejs  layout.ejs
  • 14. Configurations app.configure(function() {    // Global configurations    app.use(express.bodyParser()); // parse incoming data    app.use(express.cookieParser()); // parse cookies    app.use(express.session({ secret: ' your secret ' }); }); app.configure(' development ', function() {    // Development configurations    // i.e. Error handler to print errors and show stack? }); app.configure(' production ', function() {    // Production configurations }); Controlled by:        NODE_ENV=production node app.js
  • 15. Routing app.get(' /users ', function(req, res) {    // List user }); app.post(' /users ', function(req, res) {    // Create user    // req.body contains POST data }); app.get(' /user/:id ', function(req, res) {    // Edit user    // req.params.id contains value of :id param });
  • 16. Sanitizing Route Params app.param(' :id ', function(v) {    return parseInt(v, 10); }); app.get(' /user/:id ', function(req, res) {    res.send(' user id: ' + req.params.id); });
  • 17. Even better... var integer = function(v) {    return  parseInt(v, 10); }; app.param(' :id ', integer); app.get(' /user/:id ', function(req, res) {    res.send(' user id:  ' + req.params.id); });
  • 18. Route Param Pre-conditions app.get(' /user/:id ', function(req, res) {    var id = req.params.id;    User.get(id, function(err, user) {      if (err) return next(err);      res.send(' user ' + user.name);    }); }); app.put(' /user/:id ', function(req, res) {    var  id = req.params.userId;    User.get(id, function(err, user) {      if  (err)  return  next(err);      user.update(req.body);    }); }); Same logic every time there is :id
  • 19. Even better... var  loadUser = function(req, res, next) {    var  id = req.params.id;    User.get(id, function(err, user) {      if  (err)  return  next(err);      if  (!user)  return  next( new  Error(' invalid userId '));      req.user = user;      next();    }); }); app.get(' /user/:id ', loadUser, function(req, res) {    res.send(' user  ' + req.user.name); }); app.put(' /user/:id ', loadUser, function(req, res) {    req.user.update(req.body); });
  • 20. You can stack them... app.put(' /user/:id ', isAdmin, loadUser, function(req, res) {    req.user.update(req.body); }); app.put(' /user/:id ', function(req, res, next) {    // Verify if the current user is an admin    isAdmin(req, res, function(err) {      if  (err)  return  next(err);      loadUser(req, res, function(err, user) {        if  (err)  return  next(err);        req.user.update(req.body);      });    }); }); ...cleaner than...
  • 21. Views "Built-in" support for : Jade (Haml-like):  http://jade-lang.com/ EJS (Embedded JS):  http://embeddedjs.com/ Support for partials.
  • 22. Rendering Views app.get(' /user/:id ', loadUser, function(req, res) {    res.render(' user_edit ', {      locals: {        user: req.user,        title: ' Edit User ' + req.user.username      }    }); });
  • 23. Other useful functions... app.helpers(Object) Set functions that are available in your views app.dynamicHelpers(Object) Set helpers that require the req and res objects app.error(Function), called when: throw new Error() next(new Error())
  • 24. Interesting Links Lots of Express examples:  http://bit.ly/ExpressExamples Express Documentation:   http://bit.ly/ExpressDocs Database wrappers and ORMs: Mongoose (MongoDB, ORM-like):  https://github.com/LearnBoost/mongoose Cradle (CouchDB, HTTP wrapper): https://github.com/cloudhead/cradle Couch-ar (CouchDB, Active Record implementation): https://github.com/scottburch/couch-ar

Editor's Notes

  • #2: - brief overview of what node has built in - overview of how to use Connect is - overview of how to use ExpressJS is - ask questions at any time
  • #4: - Explain the basics of http module and createServer function. - req is object that has request stuff (url, get params, body, cookies, ..) - res is object that has response stuff (set headers, send data, ..)
  • #5: - just a very simple http wrapper - gotta code everything up on your own
  • #6: - connect makes it easier - comes with many useful bundles - typical functionalities that you will need
  • #8: - similar to node's http module - if put all in same callback, can get messy
  • #9: - use() is a different way of setting callbacks - we call them Middleware - behind use() is a stack, first in, first out - can use next() to trigger next handler - can have infinite handles
  • #10: - a better way of setting routes - HTTP verbs - capture url params using colon - can also use regular expressions - next() Error handling - don't need to use next to pass to next() handler. - can organize by module
  • #11: - stack the middlewares you want - called in order - seperate controllers into modules
  • #12: - easier than node, but still low level - No view engine, gotta add your own - Configurations, on your own - good for restful since dont need view engine - express is like sinatra - built with connect - all the features of connect, but more
  • #14: - try it out with CLI tool, its easy - multiple template engines (jade, ejs, mustache, etc...) - css compiler support (less, sass)
  • #15: - configuration blocks - can be controlled with NODE_ENV environment variable
  • #16: - Uses Connect.router - Can use HTTP verbs - Can capture params - req.body for POST - req.params for url params
  • #17: - can sanitize parameters - force type on params - some cases in couchdb that you can nosql injections. this would prevent
  • #18: - generalize formatters - reuseable
  • #19: - we want to validate user exists in both situations - we aren't reusing the code - same logic every time
  • #20: - you could also validate that the userId is an integer using same method. - and call next() if not int
  • #21: - you can add as many as you need - this example, checking login and checking user exists
  • #22: - built in ejs and jade - ejs is html with embedded JS - jade is like haml - partials, can render views inside a view
  • #23: - automatically loads views/user_edit.jade - .render automatically includes layout.jade
  • #24: - cant go through all of them, just so you know - app.helpers takes an object and exposes in views - app.dynamicHelpers when you want to use request vars - app error, 
  • #25: Interesting Links