res.locals
-middleware
to-locals: Transform callback-functions into connect middlewares, dumping their content to res.locals
.
How
npm i to-locals
var toLocals = ; // toLocals([context], function, [arguments], key) ;;;;;
What
Most node function are something like this:
var { ;};
Writing your site with express, you usually call these functions and just put their values in res.locals
:
app;
With to-locals
, it's a bit simpler:
app;
It's perfect for mongoose:
var users = ;app;
For more complicate cases you can to-locals
around an anonymous function:
var project = ;
Notice how req
(and res
) was attached to the callback!
Or use to-locals
's sugar:
var project = ;
Tests
Mocha with some npm test
.
Licence
MIT