Skip to content

Instantly share code, notes, and snippets.

@jaouadballat
Created March 3, 2018 16:38
Show Gist options
  • Save jaouadballat/ac18a972e729f6d8c2dc187de853564d to your computer and use it in GitHub Desktop.
Save jaouadballat/ac18a972e729f6d8c2dc187de853564d to your computer and use it in GitHub Desktop.
const express = require('express');
const router = express.Router();
const faker = require('faker');
const Product = require('../../models/Product');
const Category = require('../../models/Category');
router.get('/', function (req, res, next) {
const categories = ["Baby", "Movies", "Shoes", "Books", "Electronics","Computers", "Kids"];
for (let i = 0; i < 20; i++) {
let product = new Product({
name : faker.commerce.productName(),
price : faker.commerce.price(),
category: categories[Math.floor(Math.random() * categories.length)],
description : faker.lorem.paragraph(),
image: "https://images-na.ssl-images-amazon.com/images/I/4196ru-rkjL.jpg"
});
product.save();
}
for (let i = 0; i < categories.length; i++) {
let cat = new Category({
title: categories[i]
});
cat.save();
}
res.redirect('/')
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment