Create MD5 Hash in Node.js

MD5 is (atleast when it was created) a standardized 1-way function that takes in data input of any form and maps it to a fixed-size output string, irrespective of the size of the input string.

Though it is used as a cryptographic hash function, it has been found to suffer from a lot of vulnerabilities.

The hash function generates the same output hash for the same input string. This means that, you can use this string to validate files or text or anything when you pass it across the network or even otherwise. MD5 can act as a Stamp or for checking if the data is valid or not.

For example -

Input String Output Hash
hi 49f68a5c8493ec2c0bf489821c21fc3b
debugpointer d16220bc73b8c7176a3971c7f73ac8aa
satvik 18457af9e2ed5d80e3d946810e189f71
computer science is amazing! I love it. f3c5a497380310d828cdfc1737e8e2a3

If you want to generate md5 checksum in JavaScript i.e., client side (browser), please follow this article-

Create MD5 Hash in JavaScript

For creating MD5 hash in nodejs script/code, we shall use the default crypto module that comes packaged with nodejs.

const crypto = require("crypto");
let yourString = "My name is Satvik";
let hash = crypto

It's as simple as that! You do not need any fancy npm library for this.

You are good to go! Happy Coding.

Please do not use this to hash passwords and store it in your databases, prefer SHA-256 or SHA512 or other superior cryptographic hash functions for the same.