title: Node js + template replace content
body: <p>I am working to generate offer letter for employees. So I have some default template index.html:</p>
  
  <p>index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="header"&gt;
  &lt;h1&gt;Offer Letter&lt;/h1&gt;
  &lt;/div&gt;
  
  &lt;div id="name"&gt;
   Hello [[Name]],
  
  Welcome to our organization,'
  
  Details:
  
  [[Date]]    : Offer Letter Date
  [[Name]]    : Employee Name
  [[Designation]] : Designation
  [[Address]] : Communication Address
  [[CTC]]  : Cost to the Company
  
  &lt;/div&gt;
  
  &lt;div id="footer"&gt;
  Copyright
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am generate multiple offers at a time more than 300.</p>
  
  <p>So I have json data like this:</p>
  
  <pre><code>var obj = [
   { "name" : "Abc",
    "Date" : "12-12-2014",
    "Designation" : "Admin",
    "Address" : "XXXX",
    "CTC" : 3333},
  { "name" : "wefrwe",
    "Date" : "12-12-2014",
    "Designation" : "Admin",
    "Address" : "XXXX",
    "CTC" : 55},
  { "name" : "dssd",
    "Date" : "12-12-2015",
    "Designation" : "Admin",
    "Address" : "XXXX",
    "CTC" : 333},
  { "name" : "gfsc",
    "Date" : "12-1-2014",
    "Designation" : "Admin",
    "Address" : "XXXX",
    "CTC" : 22},
  { "name" : "dssdds",
    "Date" : "1-12-2014",
    "Designation" : "Admin",
    "Address" : "XXXX",
    "CTC" : 4334}
  ];
  </code></pre>
  
  <p>How do I replace values (eg. [[Name]] to Abc ) .</p>
  
  <p>Have any node packages ?</p>
  
  <p>I tried the following code but don't know this is best way and useful.</p>
  
  <pre><code>for(i in obj) {
  
  
  var textbody = '&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="header"&gt; &lt;h1&gt;Offer Letter&lt;/h1&gt; &lt;/div&gt; &lt;div id="name"&gt; Hello [[name]], Welcome to our organization,' Details: [[Date]] : Offer Letter Date [[Name]]    : Employee Name [[Designation]] : Designation [[Address]]   : Communication Address [[CTC]]  : Cost to the Company &lt;/div&gt; &lt;div id="footer"&gt; Copyright &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;';
  
  
  textbody = textbody.replace(/{[^{{}}]+}/g, function(key){
      return obj[key.replace(/[{{}}]+/g, "")] || "";
  });
  
  }
  </code></pre>