Easily share data between Browserify modules meant to run on the server and client.
The following example shares a Backbone Model between the server and browser. However, this could be applied to any module shared server/client.
var sharify = ;sharifydata =API_URL: ''NODE_ENV: processenvNODE_ENV;app;
var Backbone =API_URL = dataAPI_URL;var Artwork = moduleexports = BackboneModel
htmlbody//- Adds `sharify.data` and a convenient `sd` short hand to localsif sharify.data.NODE_ENV == 'development'#debug-modal#scripts//- Make sure this is above your other scripts!= sharify.script()script( src='/bundle.js' )
NOTE: Sharify will safely expose the
sd globals to the client-side for the convenience of sharing templates server/client.
// server.jsvar Artwork = ;app
// client.jsvar Artwork =View = ;model: ;
You can use sharify to bootstrap dynamic data as well.
Inject data into the
var Artwork = ;app;
Require the data on the client
var Artwork =ARTWORK_JSON = dataARTWORK_JSONView = ;model: ARTWORK_JSON ;
Please fork the project and submit a pull request with tests. Install node modules
npm install and run tests with