express middleware

  • best slide
  • request handler
  • build on connect middleware
    • extensible HTTP server framework for node,
    • providing high performance “plugins” known as middleware.
    • More specifically, connect wraps the Server, ServerRequest, and ServerResponse objects of node.js’ standard httpmodule, giving them a few nice extra features, one of which is allowing the Server object to use a stack of middleware.
  • it’s called as a chain of functions
    • with order based on middleware definition
    • with matching routes
    • req & res are travelling through the chain
    • also called pipeline
      • series of processing unit connected together
  • use cases
    • generic
      • apply to every single request
      • need to call next() to proceed to next middleware
    • specific
      • app.get(“/”,function(){})
  • order is the definition order
  • error
    • A middleware can also signal an error by passing it as the first argument to next:
    • // A middleware that simply interrupts every request function worseThanUselessMiddleware(req, res, next) { next(“Hey are you busy?”) }
    • When a middleware returns an error like this, all subsequent middleware will be skipped until connect can find an error handler
  • http
    • Node.js itself offers an HTTP module, whose createServer method returns an object that you can use to respond to HTTP requests
This entry was posted in Nodejs. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s