-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (33 loc) · 1.05 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
const express = require('express')
const path = require('path')
const mongoose = require('mongoose')
const Campground = require('./models/campground')
const app = express()
const port = 3003
app.set('view engine', 'ejs')
app.set('views', path.join(__dirname, './views'))
// You may need to use '127.0.0.1' instead of localhost
mongoose.connect('mongodb://127.0.0.1:27017/yelprev-01', {
useNewUrlParser: true,
useUnifiedTopology: true
});
const dbConn = mongoose.connection
dbConn.on('error', console.error.bind(console, 'connection error:'))
dbConn.once('open', () => { console.log("We are connected") })
app.get('/', (req, res) => {
res.render('home')
})
app.get('/makecampground', (req, res) => {
const myNewCampground = new Campground({
title: 'Ballybough Campsite',
price: 1.00,
description: 'Full of knackers',
location: 'Dublin',
image: 'https://source.unsplash.com/collection/483251'
})
console.log(myNewCampground)
res.send(myNewCampground)
})
app.listen(port, (req, res) => {
console.log(`Server running on Port ${port}`)
})