Shared Data Context for Node and the Browser

This module provides a middleware which is easily used to share data between the front and back end. The data is properly escaped for insertion directly into the html of a page to protect you against script injection attacks. This is a common pattern used for applications that have heavy front-end javascript components like React or Angular apps.
If you are using an isomorphic router pattern, like the Express with Nighthawk, you can use this middleware on both sides and it will handle the data loading for you. Check out the example for more details on this pattern.
Usage
$ npm install --save shared-context
var app = require('express')();
var sharedContext = require('shared-context');
app.use(sharedContext({
}));
app.get('/', function (req, res) {
res.locals.context.title = 'Foo\'s Day at the Bar';
res.render('index');
});
<html>
<script>
__context = <%- JSON.stringify(context) %>
</script>
<script src="/browser.js"></script>
</html>
var app = require('nighthawk')();
var sharedContext = require('shared-context');
app.use(sharedContext());
app.get('/', function (req, res) {
console.log(res.locals.context.title);
});