Skip to content

Instantly share code, notes, and snippets.

@iamgoangle
Last active June 10, 2017 12:18
Show Gist options
  • Select an option

  • Save iamgoangle/2710fea5968e154d6959ad8248047f40 to your computer and use it in GitHub Desktop.

Select an option

Save iamgoangle/2710fea5968e154d6959ad8248047f40 to your computer and use it in GitHub Desktop.
products.js
// products.js
var faker = require('faker');
function generateProducts () {
let products = [];
for (var id = 0; id < 50; id++) {
var productName = faker.commerce.productName();
var price = faker.commerce.price();
var qty = faker.finance.amount();
products.push({
"id": id,
"productName": productName,
"price": price,
"qty": qty
});
}
return { "products": products };
}
// json-server requires that you export
// a function which generates the data set
module.exports = generateProducts();
{
"products": [
{
"id": 0,
"productName": "Handcrafted Metal Shoes",
"price": "425.00",
"qty": "508.54"
},
{
"id": 1,
"productName": "Ergonomic Fresh Hat",
"price": "548.00",
"qty": "571.30"
},
{
"id": 2,
"productName": "Sleek Wooden Pizza",
"price": "705.00",
"qty": "581.94"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment