Faker.js

It’s a wonderful node module to create fake/mock data.

Faker.js has its own API, and it’s huge.

It has a vast API for almost every use case with an excellent documentation

Let’s consider a test case where I want some a user to have following amount of fields:

  • name

  • email

  • website

  • address

  • bio

  • image/avatar

1
2
3
4
5
6
7
8
9
10
const faker = require('faker')

const User = {
name: faker.name.findName(),
email: faker.internet.email(),
website: faker.internet.url(),
address: faker.address.streetAddress() + faker.address.city() + faker.address.country(),
bio: faker.lorem.sentences(),
image: faker.image.avatar(),
}

Faker.js Data

List of data that can generate faker.js:

  • address

  • commerce

  • company

  • date

  • finance

  • hacker

  • helpers

  • image

  • internet

  • lorem

  • name

  • phone

  • random

  • system

Use in Browser

1
2
3
4
<script src='faker.js'></script>
<script>
var randomName = faker.name.findName()
</script>