Tools for Seeding Databases in Node.js

Multiple tools for seeding a database for projects, personal and or professional.

In this post, I’ll be discussing some tools I’ve found and used for different projects of mine. Why would we want to seed a database? There are typically a couple of reasons to seed a database. First, having data in your database is typically helpful for tests that need to hit the database. The second reason to seed a database is to show off a project, for example, a portfolio piece or an internal demonstration of something you developed for your company. There are two categories of tools I’m listing. A data-oriented tool, and a few avatars tools.

Starting with the data-oriented tool, an NPM package, Chance. I love the variety of data that this tool can generate. Need to randomly generate an address? Chance can do it. Need random sentences? No problem. There are many different things that Chance can generate. I strongly suggest you check their documentation for the wide, and I do mean wide, variety of things it can generate.

What I find helpful, especially when using Chance in code tests, you can set a seed value for the pseudorandom generator that Chance uses. This way every time you run your program, as long as you invoke Chance’s functions in the same order, you will get repeatable results.

There is, however, one feature so far that I don’t like. That is Chance’s ability to generate avatar URLs. When invoked, it generates random Gravatar URLs that typically do not result in a meaningful avatar but rather the Gravatar logo as seen here below.

Gravatar Logo

The next 3 tools are all static image generators. The intent is to be used as image placeholders typically for profiles. All 3 tools are simple RESTful APIs where a simple URL is all you need. The cat image below was generated by going to the following URL in the browser and saving the image. Of course, we can do this programmatically too.

Cute cartoon kitty cat

What’s nice is all of these APIs take in some value (in the example above, whatever) that will generate a unique image. The same image will be generated by the same phrase over and over again so it is repeatable. However, change that value and a completely different image will be generated.

Starting off with my favorite, RobotHash, with which I used to generate the image below. This site is my favorite as I just happen to like robots. The site, if you read the short documentation (right on the home page) will also allow you to create monsters, humans, and cats (that cute kitty above is an example).

Cute cartoon robot

Next up we have DiceBear Avatars. This tool has two notable features. First, it can generate ten categories of images (sprites) including this pixilated male image below, and yes they have a female option too. Notably one of the options, code, generates QR codes. The second feature, is they provide an npm package with lots of advanced options for each sprite.

Pixilated cartoon man

Last but not least is Adorable Avatars. Of the three generators, this site has the least amount of options. Pretty much you get a square cartoonish face, such as this one below.

Square cartoon creature

The last tool I want to mention is Cartoon Avatars. This is an npm package that will randomly select URLs that resolve to cartoon avatars. What I like about these is that they are human placeholders and I can select male or female as an option. What should be noted is these images are not randomly generated, but rather randomly selected. There are 129 male avatars and 114 female avatars. That I believe should be enough for most projects.

Cartoon avatar of a woman

This post has been cross-posted on Medium

Aaron Young © 2020. All rights reserved.