-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (27 loc) · 834 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const mongoose = require('mongoose');
const scraper = require('./scraper');
const url = 'https://www.delish.com/cooking/recipe-ideas/recipes/a52422/brunch-punch-recipe/';
// database
mongoose.connect('mongodb://localhost:27017/delish', {useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true,});
const db = mongoose.connection;
// get scraped recipe object
scraper.scrapeRecipe(url)
.then((recipe) => {
console.log(recipe);
})
.catch((err) => {
console.error(err);
});
// get scraped recipe database model
scraper.scrapeRecipeModel(url)
.then((recipe) => {
console.log(recipe);
recipe.save((err, recipe) => {
if (err) {
console.error(err);
}
});
})
.catch((err) => {
console.error(err);
});