Datastore API: How to calculate MD5 hash in Node.js

In order to set entries and increment entries, you may be required to pass the md5 hash as a header in your POST request to the Datastore API. ROBLOX gives an example on how to do this in Python on their post here: Datastore API.

I however, like many other developers use Node.js for most of my off-platform applications. Because of this, I am going to be posting some code that can calculate the md5 for you in Node.js. I struggled to find a proper example online, so here you go:

const crypto = require('crypto'); // Require the crypto module built into node.

let data = "Test Data"; // Where data is in the form of a String.

crypto.createHash('md5').update(data).digest('base64'); // Create the md5 hash.

And you’re done! Just make sure to pass your data through as a String when using this function. If you have data that is not yet formatted as json, just use:

JSON.stringify(your_data_here);

This will take your data and turn it into a json string format for you.

Hopefully this code will help you out, if you have any questions be sure to let me know!

6 Likes