title: Sharing handlebars templates between server and client with browserify
body: <p>Goal: I don't want to have to duplicate templates, partials, and helpers for handlebars. I want to re-use them in the client and on the server.</p>
  
  <p>Problem: When registering helpers on the client side, it doesn't work.</p>
  
  <p>Stack: Node.js (with express), handlebars.js, browserify</p>
  
  <p>NPM modules being used: <code>browserify-handlebars</code>, <code>express-handlebars</code></p>
  
  <p>In my <strong>client</strong> side I have the following file:</p>
  
  <pre><code>var Handlebars = require('handlebars');
  
  Handlebars.registerHelper('json', function(obj) {
      return JSON.stringify(obj);
    });
  
  var aTemplateFunction = require('../../templates/blah.handlebars');
  
  
  var html = aTemplateFunction({
    someObject: {
      'key': 'value'
    }
  });
  </code></pre>
  
  <p>I have browserify running on it to compile the template.</p>
  
  <p><code>../../templates/blah.handlebars</code> is:</p>
  
  <pre><code>{{ json someObject }}
  </code></pre>
  
  <p>It will compile the template fine, but it won't apply the helper properly. The error I get is:</p>
  
  <p><code>Uncaught Error: Missing helper: 'json'</code></p>
  
  <p>What am I doing wrong here?</p>
  
  <p>Additional question: I found this example (<a href="http://codyrushing.com/using-handlebars-helpers-on-both-client-and-server/" rel="nofollow">http://codyrushing.com/using-handlebars-helpers-on-both-client-and-server/</a>) about sharing helpers between the client and server, but it seems like more of a hack to me. </p>
  
  <p>What's the proper way to share helpers between the client and server?</p>