-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (36 loc) · 1.15 KB
/
app.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
37
38
39
var express = require('express'),
app = express(),
request = require('request'),
mongoose = require('mongoose'),
cheerio = require('cheerio'),
Film = require('./models/film'),
Screening = require('./models/screening'),
Type = require('./models/type');
// scotiaTheatre = require('./scrape/scotiaTheatre');
app.set('view engine', 'ejs');
mongoose.connect("mongodb://localhost/to_movies", { useNewUrlParser: true });
// ROUTES
app.get("/", function(req, res){
// populating multiple feilds and multiple seeded documents.
Film.find().
populate({
path: 'screenings types',
populate: {
path: 'types'
}
})
.exec(function(err, foundFilms){
if(err){
console.log(err);
console.log('couldnt find the FILMS!');
res.redirect('back');
} else {
console.log('found the FILMS!');
res.render('home', {films: foundFilms});
}
});
});
// LISTENER
app.listen(process.env.PORT || 3000, function(){
console.log('your server has started!');
});