Created
March 3, 2018 16:38
-
-
Save jaouadballat/ac18a972e729f6d8c2dc187de853564d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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