Under the Hood

Today's story will be short and informative. As usual, we always start our story with the under the hood concept. Here we defined how we got the idea of writing this story.

We were developing a profile page for the developers on our platform. And instead of a user image, we want to show the cool avatars and here we come with the solution.

Getting Started

We found an npm node js library that helps to give the user avatar link. The library is just like any other npm module that exports the method which returns the avatar link. You can further store the link in the database as the user profile image.

Npm Module

Please note, the internet is full of tonnes of libraries to deal with cool avatars. If you find the one that is first perfect for you please let us know in the comment section, until then enjoy the one we are sharing with you.

Library: https://www.npmjs.com/package/cartoon-avatar

yarn add cartoon-avatar

Execution

Once the package is installed you just need to import the method to create an avatar.

You can pass the options as the params to the generate_avatar function to create the avatar according to your need.

Passing Options

The options consist of the following params โ€”

  • gender โ€” Describe the gender of the avatar
  • id โ€” unique identifier of the avatar

On the basis of the options passed the generate method will return the user avatar link. You can directly store the link in the database also and render them as an image.

Node JS or Next JS

You can use the library either in the node js application or in the next js on the client-side. But with next js invoke the method generate avatar only using serverless functions. If you don't know what is a serverless function, here is the link to the story.

Conclusion

The story is short and informative, we are planning to share such stories more often to quietly serve such information. So do subscribe and follow us, until, next time, have a good day, people.

Our website - iHateReading