Using SHA-256 with NodeJS Crypto

nodejs (8) ref

const crypto = require('crypto');
const hash = crypto.createHash('sha256');

hash.on('readable', () => {
    const data = hash.read();
    if (data) {
        console.log(data.toString('hex'));
        // Prints:
        //  6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
    }
});

hash.write('some data to hash');
hash.end();

you can use, like this, in here create a reset token (resetToken), this token is used to create a hex version.in database, you can store hex version.

// Generate token
 const resetToken = crypto.randomBytes(20).toString('hex');
// Hash token and set to resetPasswordToken field
this.resetPasswordToken = crypto
    .createHash('sha256')
    .update(resetToken)
    .digest('hex');

console.log(resetToken )

base64:

const hash = crypto.createHash('sha256').update(input).digest('base64');

hex:

const hash = crypto.createHash('sha256').update(input).digest('hex');