title: Using hogan.js with express.js + vhosts
body: <p>What is the correct way to use hogan.js with express.js?</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>var hogan = require('hogan.js')
  ...
  app.set('view engine', 'hogan');
  </code></pre>
  
  <p>followed by</p>
  
  <pre><code>app.register('.hogan', hogan);
  </code></pre>
  
  <p>But I end up with the following error:</p>
  
  <pre><code>500 Error: Cannot find module 'hogan'
  </code></pre>
  
  <p>TJ put out a library called consolidate.js ( <a href="https://github.com/visionmedia/consolidate.js" rel="nofollow">https://github.com/visionmedia/consolidate.js</a> ) but I'm having trouble getting it to work with Express 2.5.8.  After spending the day trying to figure this out I also came across a library called hulk-hogan.js ( <a href="https://github.com/quangv/hulk-hogan" rel="nofollow">https://github.com/quangv/hulk-hogan</a> ) and another called hogan-express ( <a href="http://allampersandall.blogspot.com/2011/12/hoganjs-expressjs-nodejs.html" rel="nofollow">http://allampersandall.blogspot.com/2011/12/hoganjs-expressjs-nodejs.html</a> ).  But, do I really need all that?</p>
  
  <p>If the solution can  not be as simple as setting the templating engine with app.set() and app.register(), it would be great if someone could help me understand why.  I'm using Hogan on the client and it's working great, it would just be so much better if I could also use it on the server.</p>
  
  <p>UPDATE: Turns out there are two issues here.</p>
  
  <ol>
  <li>While this is not causing the <code>500 error</code>, Express does not work with Hogan out of the box (see: Linus G Thiel's answer below)</li>
  <li>What seems to be causing the <code>500 error</code> is that I'm using a virtual host and when I call res.render(), my res.render() call is actually calling the res.render() of a different virtual host on my same server.</li>
  </ol>
  
  <p>Adding the full Express error dump.  It looks like my app ('dataviz') is trying to use the render call from a different app ('datavizblocks')?  Again, the two apps are virtual hosts on the same server.</p>
  
  <pre><code>dataviz 8000
  Error: Cannot find module 'hogan.js'
      at Function._resolveFilename (module.js:332:11)
      at Function._load (module.js:279:25)
      at Module.require (module.js:354:17)
      at require (module.js:370:17)
      at View.templateEngine (/localhost/datavizblocks/node_modules/express/lib/view/view.js:134:38)
      at Function.compile (/localhost/datavizblocks/node_modules/express/lib/view.js:68:17)
      at ServerResponse._render (/localhost/datavizblocks/node_modules/express/lib/view.js:417:18)
      at ServerResponse.render (/localhost/datavizblocks/node_modules/express/lib/view.js:318:17)
      at /localhost/dataviz/routes/section.js:325:7
      at callbacks (/localhost/dataviz/node_modules/express/lib/router/index.js:272:11)
  dataviz 8000
  Error: Cannot find module 'hogan.js'
      at Function._resolveFilename (module.js:332:11)
      at Function._load (module.js:279:25)
      at Module.require (module.js:354:17)
      at require (module.js:370:17)
      at View.templateEngine (/localhost/datavizblocks/node_modules/express/lib/view/view.js:134:38)
      at Function.compile (/localhost/datavizblocks/node_modules/express/lib/view.js:68:17)
      at ServerResponse._render (/localhost/datavizblocks/node_modules/express/lib/view.js:417:18)
      at ServerResponse.render (/localhost/datavizblocks/node_modules/express/lib/view.js:318:17)
      at /localhost/dataviz/routes/section.js:325:7
      at callbacks (/localhost/dataviz/node_modules/express/lib/router/index.js:272:11)
  </code></pre>
  
  <p>The <code>500 error</code> goes away when I comment out the <code>datavizblock</code> vhost, or when I switch the order of the vhost declarations around to have the <code>dataviz</code> vhost declared after <code>datavizblocks</code> vhost (of course, this then causes problems for the <code>datavizblocks</code> vhost)</p>
  
  <p>Apologies ahead of time for the confusing question, but I was really confused when I came across this issue and never expected that switching to <code>Hogan</code> would have conflicts with  virtual hosting.</p>