How to Generate Gravatar Images with JavaScript/Node

Posted by Josh on March 09, 2019

Someone asked a question at the meetup today on how to create avatars on a site. The fastest method is probably to use Gravatar. Gravatar is a service that displays user profile pictures based on their email addresses. If the user hasn't signed up with Gravatar, a variety of default avatars can be shown.

Here is my Gravatar as an example:

In the simplest form, you load an image that is built with this structure:

https//www.gravatar.com/avatar/<md5sum_of_email_address>

Here's a solution that will work in Node.js, and allow you to choose a different type of default image for when an email address doesn't have a Gravatar: