High performance middleware framework
Connect is an extensible HTTP server framework for node using "plugins" known as middleware.
var connect = ;var http = ;var app = ;// gzip/deflate outgoing responsesvar compression = ;app;// store session state in browser cookievar cookieSession = ;app;// parse urlencoded request bodies into req.bodyvar bodyParser = ;app;// respond to all requestsapp;//create node.js http server and listen on porthttp;
Connect is a simple framework to glue together various "middleware" to handle requests.
$ npm install connect
The main component is a Connect "app". This will store all the middleware added and is, itself, a function.
var app = ;
The core of Connect is "using" middleware. Middleware are added as a "stack"
where incoming requests will execute each middleware one-by-one until a middleware
does not call
next() within it.
.use() method also takes an optional path string that is matched against
the beginning of the incoming request URL. This allows for basic routing.
There are special cases of "error-handling" middleware. There are middleware where the function takes exactly 4 arguments. Errors that occur in the middleware added before the error middleware will invoke this middleware when errors occur.
The last step is to actually use the Connect app in a server. The
is a convenience to start a HTTP server.
var server = app;
The app itself is really just a function with three arguments, so it can also be handed
.createServer() in Node.js.
var server = http;
These middleware and libraries are officially supported by the Connect/Express team:
urlencoded. You may also be interested in:
Most of these are exact ports of their Connect 2.x equivalents. The primary exception is
Some middleware previously included with Connect are no longer supported by the Connect/Express team, are replaced by an alternative module, or should be superseded by a better module. Use one of these alternatives instead:
Checkout http-framework for many other compatible middleware!
npm installnpm test
< 1.x- node
< 2.8- node
>= 2.8 < 3- node
>= 3- node