title: Rendering HTML template with EJS in a callback for asynchronous fs.readFile?
body: <p>I easily accomplished this with the fs.readFileSync but I want to do this asynchronously. My code follows.</p>
  
  <pre><code>    function send(err, str){
  
          if(err){
              console.log(err);
          }
  
          var template = ejs.render(str, 'utf8', {name: data.name});
  
          transporter.sendMail({
              from: myEmail,
              to: anotherEmail,
              subject: mySubject,
              html: template,
              attachments: images
          }, function(err, response) {
              if(err){
                  console.log(err);
              }
          });
      }
  
      fs.readFile('emailTemplate.ejs', send);
  </code></pre>
  
  <p>So I made my own callback for fs.readFile so that when the file has been read it will render the email, putting the proper name in and then send it off with nodemailer. However, it does not like this. It gets by the error if no problem but render throws the following error when it tries to render the template. </p>
  
  <blockquote>
    <p>TypeError: Object (Followed by the entire HTML of the template) has no method 'indexOf'
        at Object.exports.parse (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:144:21)
        at exports.compile (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:229:15)
        at Object.exports.render (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:289:10)
        at send (/home/ubuntu/workspace/routes/email.js:171:28)
        at fs.readFile (fs.js:272:14)
        at Object.oncomplete (fs.js:108:15)</p>
  </blockquote>
  
  <p>Doing it synchronously works fine though.</p>
  
  <pre><code>    var str = fs.readFileSync('emailTemplate.ejs', 'utf8');
  
      var template = ejs.render(str, {
          name: data.name
      });
  </code></pre>
  
  <p>Can anyone give me any insight into why this is happening?</p>