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");
shasum.update("foo");
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
.