You can also make use of Buffer Output :
var crypto = require('crypto');
var hash = crypto.createHash('sha256');
var code = 'bacon';
hash.update(code);
var hashedCode = hash.digest(); // Returns a buffer
console.log(hashedCode.toString('hex')); // Convert buffer to hex