Skip to content

Instantly share code, notes, and snippets.

@remarkablemark
Last active December 12, 2018 17:17
Show Gist options
  • Save remarkablemark/ef52f3fb1c16cf7aaf8aae1fc81aceca to your computer and use it in GitHub Desktop.
Save remarkablemark/ef52f3fb1c16cf7aaf8aae1fc81aceca to your computer and use it in GitHub Desktop.
Calculate the MD5 hash of a string using Node.js
'use strict';
/**
* Module dependencies.
*/
var crypto = require('crypto');
/**
* Calculates the MD5 hash of a string.
*
* @param {String} string - The string (or buffer).
* @return {String} - The MD5 hash.
*/
function md5(string) {
return crypto.createHash('md5').update(string).digest('hex');
}
module.exports = md5;
@antydemant
Copy link

@remarkablemark
I think, .update(data) should be .update(string) in this example

@remarkablemark
Copy link
Author

@antydemant Thanks for the catch! I updated the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment