-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (29 loc) · 1.12 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
// Setup
// -----------------------------------------------------------------------------
// #############################################################################
const express = require("express");
const mongoose = require("mongoose");
const Cat = require("./cat-model.js");
// connect to the database defined by this CONNECTION STRING
// (domain, port, database name, and all info about the database)
mongoose.connect("mongodb://localhost/cat-ebay");
const app = express();
app.listen(3000, () => {
console.log("Meow! Server ready. 😸");
});
app.use(express.static(__dirname + "/public"));
app.set("view engine", "hbs");
// Routes
// -----------------------------------------------------------------------------
// #############################################################################
app.get("/", (request, response, next) => {
Cat.find({ toys: { $ne: null } })
.then(catResults => {
response.locals.catArray = catResults;
response.render("cat-list.hbs");
})
.catch(err => {
console.log("HOME PAGE Cat.find() failure 💩", err);
response.render("cat-error.hbs");
});
});