Skip to content

Instantly share code, notes, and snippets.

@kosinix
Created May 7, 2024 13:07
Show Gist options
  • Save kosinix/758fdb3c5d0257bf1025afaa331bbba0 to your computer and use it in GitHub Desktop.
Save kosinix/758fdb3c5d0257bf1025afaa331bbba0 to your computer and use it in GitHub Desktop.
Generate hash of text file contents Nodejs for checksum
const crypto = require('crypto')
const { readFileSync } = require('fs')
const getHash = (fileBuffer) => {
const hashSum = crypto.createHash('sha256')
hashSum.update(fileBuffer)
const hex = hashSum.digest('hex')
return hex
}
let file = readFileSync(`file.txt`)
getHash(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment