How to create a hash string with Node.js?

Sometimes, we want to create a hash string with Node.js.

In this article, we’ll look at how to create a hash string with Node.js.

How to create a hash string with Node.js?

To create a hash string with Node.js, we can use the crypto module.

For instance, we write

const crypto = require('crypto');
const name = 'hello';
const hash = crypto.createHash('md5').update(name).digest('hex');

to call crypto.createHash with 'md5' to create a new hash string.

And we call update to create the hash string hashed from name.

Finally, we call digest with 'hex' to return the hashed string as hex.

Conclusion

To create a hash string with Node.js, we can use the crypto module.