title: What encoding should I use to properly generate an ETag with crypto in nodeJS?
body: <p>In my nodeJS app, I'd like to generate ETags for all the content that I return to the client. I need the ETag to be based off the actual content of the file instead of the date, so that the same file across different node processes has the same ETag. </p>
  
  <p>Right now, I am doing the following:</p>
  
  <pre><code>var fs = require('fs'), crypto = require('crypto');
  fs.readFile(pathToFile, function(err, buf){
    var eTag = crypto.createHash('md5').update(buf).digest('hex');
    res.writeHead(200, {'ETag': '"' + eTag + '"','Content-Type':contentType});
    res.end(buf);
  });
  </code></pre>
  
  <p>I am not sure what encodings I should be using for the different crypto functions in order to have a proper system in place. Should I be using something other than <code>hex</code>? Should I get the <code>fs.readFile</code> call to return a hex encoded buffer? If so, will doing so impact the content returned to users? </p>
  
  <p>Best, and Thanks,<br/>Sami</p>