Hash text in Node.js

Hash a text using native crypto module in Node JS. No extra dependencies.

Andres Canavesi
Aug 02, 2020
Hash a string in Node.js without extra dependencies
featured image
const crypto = require('crypto');
const stringToHash = 'hello';
const hash = crypto.createHash('sha256').update(stringToHash).digest('hex');
// the output will be something like: 20ccfac05d596dfb08509494fc7753780ac6d79a23c88ef02514f4c5b2a3ff45

// instead of .digest('hex'); you can use also .digest('base64');
Photo by Rick Mason on Unsplash