Need A Lot Of Fake Data, Real Quick?

Say no more, for faker.js has you covered!

Faker.js is fake data generator implemented for nodejs and the browser. From zip codes to avatars to account names to hacker phrases, faker.js comes equipped with a huge dataset.


Use In The Browser

<!-- Just link to faker.js in your html through their CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Faker/3.1.0/faker.js"></script>
<!-- or your local download -->
<script src=”/path/to/faker.js”></script>

NodeJS

Install the dependency into your directory:

npm install -S faker

Then create an index.js and inside require faker:

const faker = require(‘faker’);

API Service

Faker even has a hosted API you can make http requests to for random data. Here's how you can make a http request for data using the fetch method in javascript:

fetch(`http://faker.hook.io?property=${METHOD}`);

and using curl:

curl http://faker.hook.io?property=METHOD

How To Use

Once you have faker installed, you will have access to the faker object. This object is filled with subcategories of data (address, company, database, date, hacker, image, internet, name, phone, random…).

Each subcategory has a set of methods that, when called, will return some data based on method called.

Example:

Input (nodejs)
Output

You can even change the localization by changing faker.locale (the default is english)

faker.local = “fr”; // language is set to French

faker.local = "es"; // language is set to Spanish

API

Receiving from the API is just as easy!

Ajax example:

ajax
ajax output

Curl Example:

cURL

Additional Features

You can seed results by using faker.seed.

You can use faker.fake for combining different methods.

Like what you read? Give Cain Watson a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.