How to sha1 hash with Node.js

Updated

You don't need to install external packages to hash a string using the SHA-1 hashing method.

Node.js comes with a built-in package called crypto that you can use. Here's a simple way:

const crypto = require('crypto')

const str = 'This is the string I want to hash.'
const hash = crypto.createHash('sha1').update(str).digest('hex')

The resulting hash is str, hashed using SHA-1 to create a shorter string that is fairly unique to the original string.

This page is referenced in: Coding Blog