Need A Lot Of Fake Data, Real Quick?

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

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


Install:

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 to your local download:

<script src=”/path/to/faker.js”></script>

…And you’re set!

NodeJS

Install the dependency into your directory:

npm install faker

Then create an index.js and inside require faker:

var faker = require(‘faker’);

…And now you have access to faker.js!

API Service

faker.js even has a hosted API you can request random data from. Heres how you could fetch data using ajax:

$.ajax({ 
 url: "http://faker.hook.io?property=" + METHOD, 
 type: "GET", 
 contentType: "json", 
 success: function(data) { console.log(data); } 
});

and using curl:

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


How To Use

Once you have faker.js 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

…And again…

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.

Show your support

Clapping shows how much you appreciated Cain W’s story.