Generating Fake Data in json-server

Posted in Uncategorized

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

Continuing from previous tutorials here and here, we first install the npm modules faker and lodash to generate fake data.

Then add new file “generator.js” which is a module.exports of a function that returns a movie object …

This function requires faker and lodash. We use lodash “times” method to run a function five times. The i is the zero-based index of the times run. We use that for our movie id. Each time the function runs, it returns an movie object which then ends up in the “movies” array.

The title of the movie is generated by faker outputting from dummy lorem ipsum words. Doing the same for getting a random name and then the year.

And there you have it…


Related Posts

Tags

Share This