Express monkey-patch to support Streamline syntax.
Supports Express 2 through 5.
var express = require'express-streamline';var app = express;// ...appuseif reqsessionuserIdreqcurrentUser = UsergetByIdreqsessionuserId _;;// ...appget'/photos'var photos = reqcurrentUsergetPhotos_;resrender'photos'photos: photos;;
npm install express-streamline --save
You can either
require() Express normally and then patch it:
var express = require'express';require'express-streamline';
require() this module, which returns the patched Express for
var express = require'express-streamline';
Then, you can write any and all Express handlers in Streamline syntax by just
// middleware handlers:appuse ;appparam'user' ;// route handlers:appget'/:user' ;apppost'/:user' ;// ... (all verbs supported)// error handlers:appuse ;
By default, Streamlined middleware handlers will continue to the
middleware, while Streamlined route and error handlers won't.
This is generally what you want, but you can specify whether
called by explicitly returning
// middleware to blacklist banned IP addresses,// but allow all other requests to pass through:appusevar isBanned = dbbannedIPssearchreqips _length > 0;if isBannedressend403;return false; // end the response;
This module also supports Streamline's smart global context. If present, the context is reset for every request, so data can safely be added to it without affecting other requests.
var globals = require'streamline/lib/globals';// middleware to set a global `locale` variable on every request,// for lower-level modules to use:appuse// parse locale... then:globalscontextlocale = locale;;
If you run into any issues, file a bug!
MIT. © 2012-2015 Aseem Kishore.
streamline-express for the
inspiration and motivation.
streamline-express has supported Express 3 for longer than this module, and
it currently also supports more advanced Express 3 features (like passing
multiple Streamlined handlers to the same
I believe this module has a cleaner API and more robust implementation,
however, but I'm biased. =) Both modules get the job done just fine!