node.js hash string?

Harry picture Harry · May 4, 2011 · Viewed 241.1k times · Source

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

braitsch picture braitsch · Aug 8, 2012

If you just want to md5 hash a simple string I found this works for me.

var crypto = require('crypto');
var name = 'braitsch';
var hash = crypto.createHash('md5').update(name).digest('hex');
console.log(hash); // 9b74c9897bac770ffc029102a200c5de