DEV Community

Cover image for Number #1 Problem for Developers - Solved!
Tuomo Kankaanpää
Tuomo Kankaanpää

Posted on

Number #1 Problem for Developers - Solved!

One of the most difficult things in programming is coming up with variable names. If the situation is even a bit more complex, I always end up either coming up with bad non-describing name or just taking way too much time thinking of the name.

Variable naming is hard. But one thing that is maybe even harder is thinking of dummy data I can input and test my application with. Lorem ipsum can only do so much. When I need to create for example dummy users, it is just difficult to make up a user name or email, not to mention other info that a user might have, say for example an address.

I have a feeling that I am not alone with this. That is why I wrote this post. Because to be honest I no longer have this issue, thanks to Faker.js.

Faker.js

Faker.js is a fake data generator for JavaScript. We can use it to generate massive amounts of fake data in the browser and node.js. They have a long list of properties we can generate and I won't list all of them here (you can check it out here) but to mention few, you can e.g. generate user names, avatars, emails, location, address, etc.

Usage and the API is very easy and straight forward to use. If we want to use Faker.js in the browser and generate a user name and email, we can do it as follows.

<script src = "faker.js" type = "text/javascript"></script>
<script>
  var randomName = faker.name.findName(); // Caitlyn Kerluke
  var randomEmail = faker.internet.email(); // [email protected]
</script>
Enter fullscreen mode Exit fullscreen mode

So first we include faker.js file and then generate the name using faker. and the respective method name (you can find all the available methods from the documentation).

If we want to test Faker.js out, they have a demo site where we can poke around and get a better understanding of all the kind of data we can generate with it. The demo site is found here.

I hope you found this post helpful and learned something new. I have a YouTube channel where I consistently upload more videos and tutorials about web development. Go ahead and subscribe to the channel to get posted on all the new uploads!


Originally published at codepulse.blog on May 9, 2020.

Top comments (6)

Collapse
 
44a6z22 profile image
HAMDAOUI Hamza • Edited

There is also a PHP version of this library Called Faker Too. Same Concept , Providing dummy Data.
It's Already Supported by PHP frameworks such as Larevel , Symfony .

Collapse
 
tumee profile image
Tuomo Kankaanpää

That's good to know, thanks!

Collapse
 
kaleman15 profile image
Kevin Alemán

I'll always prefer the good old chancejs.com/. A beautiful library with a good API

Collapse
 
tumee profile image
Tuomo Kankaanpää

Cool! I haven't heard of that before, gotta check it out too!

Collapse
 
adsidera profile image
Anna Costalonga

Ah I like Faker! As a Rubyst, I normally use the Faker gem :) (which I even contributed to ;) )

Collapse
 
alexkhismatulin profile image
Alex Khismatulin • Edited

For those who struggle with this problem in browser, there's an extension called Fake Data