Harry Harry -4 years ago 253
Node.js Question

node.js hash string?

I have a string that I want to hash. What's the easiest way to generate the hash in node.js?

The hash is for versioning, not security.


Answer Source

Take a look at crypto.createHash(algorithm)

var filename = process.argv[2];
var crypto = require('crypto');
var fs = require('fs');

var md5sum = crypto.createHash('md5');

var s = fs.ReadStream(filename);
s.on('data', function(d) {

s.on('end', function() {
  var d = md5sum.digest('hex');
  console.log(d + '  ' + filename);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download