You can use the built-in crypto
module in Node.js to generate the MD5 checksum of a file as follows:
index.tsx221 chars7 lines
In the above code, we first include the crypto
module to access the hash functionality. Then we create a Hash object with the createHash
method and specify the algorithm as md5
. We update the hash with the image buffer using the update
method and finally generate the checksum in hexadecimal format using the digest
method.
Note that if you want to compute the checksum of a file stored on disk, you need to read it into a buffer first. You can use the fs
module to read the file and then pass the buffer to the update
method.
gistlibby LogSnag