title: Node js - Compile handlebars view without rendering it
body: <p>My problem is simple: I want to compile a Handlebars view then not render it - instead I want to use the compiled HTML server side. While researching the problem, <a href="https://stackoverflow.com/questions/30030551/node-express-how-to-render-handlebars-html-page-to-file">this</a> was the closest to my problem that I could find, but unless I'm misunderstanding, all their doing in this question is creating an HTML string server-side and populating it with data. It's insufficient because I don't want to create any HTML strings, I literally want to keep my HTML stored in <code>.hbs</code> files, as usual, and then compile a view (i.e. send it my variables), then instead of displaying it to a user (which won't be possible anyway because it's an API server only), I want to have the compiled HTML to send it on to Mailgun (but the fact that I want to send it to Mailgun is outside the scope, answers should preferably only tell me how to compile the view and be able to (for instance) <code>console.log()</code> the HTML). </p>
  
  <p>I'm using Node v9.8.0</p>
  
  <p>Packages:</p>
  
  <ul>
  <li>body-parser: 1.18.3</li>
  <li>cors: 2.8.4,</li>
  <li>dotenv: 5.0.1,</li>
  <li>express: 4.16.3,</li>
  <li>hbs: 4.0.1</li>
  <li>moment: 2.22.1</li>
  </ul>
  
  <p>Let me know if I need to supply any additional information and the reason that I haven't included any example code of what I've tried is that I have literally no idea what to even try. All I've tried was <code>let emailHtml = res.render('email/contactReceipt.hbs', { name:req.body.name })</code> inside my route but that gave me the error <code>Cannot set headers after they are sent to the client</code>.</p>
  
  <p><strong>Side Note:</strong> I am fairly new to Node.js and it's not part of my normal stack. I have noticed that other people use the package 'express-handlebars' and even just 'handlebars' so if what I'm using ('hbs') is actually in no way related to Handlebars, or if I won't be able to accomplish what I'm trying to do because of it, let me know.</p>