JavaScript Answers

How to get the sha1 hash of a string in Node.js?

Spread the love

To get the sha1 hash of a string in Node.js, we can use the crypto module.

For instance, we write

const crypto = require("crypto");
const shasum = crypto.createHash("sha1");
const digest = shasum.digest("hex");

to call crypto.createHash to create the shasum hash object.

Then we call shasum.update to update the hash with the 'foo' string.

And then we return the hash digest with digest.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.