node hash string code example

Example 1: Create MD5 hash with Node.js

var string = 'some string';
var crypto = require('crypto');
var hash = crypto.createHash('md5').update(string).digest('hex');
console.log(hash);

Example 2: Create MD5 hash with Node.js

var crypto = require('crypto');
var hash = crypto.createHash('md5').update(string).digest('hex');
console.log(hash);

Example 3: nodejs hashing

const crypto = require('crypto');

const secret = 'abcdefg';
const hash = crypto.createHmac('sha256', secret)
                   .update('I love cupcakes')
                   .digest('hex');
console.log(hash);
// Prints:
//   c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e