Generating a MD5 hash in NodeJS

A few days ago I wanted to integrate gravatar in one of the applications I’v been working on, and realized gravatar still uses MD5 for hashing the user’s email.

I was wondering whether I would need an external module to generate the hash, but quickly realized the native crypto can do the trick:

1
2
3
const crypto = require('crypto')

let hash = crypto.createHash('md5').update('some_string').digest("hex")

It really doesn’t get any easier than that — adios!


In the mood for some more reading?

...or check the archives.