middleware-render

render middleware

middleware to render arbitrary views. This middleware can be used with all existing template engines.

Middleware called before render should populate the req.loaded object with data that the view should present to the client render will send the output of view req.loaded to the client

jsonView = (params) -> JSON.stringify params

router.get '/resource',
    (req, res, next) ->
        req.loaded =
            foo: 'bar'
            fitz: [1..10]
        next()
    render jsonView

// will render `'{"foo":"bar","fitz":[1,2,3,4,5,6,7,8,9,10]}'` to the
// client

This middleware was implemented with snd while hacking together on a project. I cleaned up the code and added some tests.