-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 1.11 KB
/
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
37
38
39
40
41
42
43
44
45
46
const express = require('express')
const app = express()
const router = express.Router();
const bodyParser = require('body-parser');
const template = require('pug');
const path = require('path');
require('dotenv').config()
app.use(express.static(path.join(__dirname, 'public'))); // "public" off of current is root
app.set('view engine', 'pug');
app.set('views', './views')
// Fire database
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGODB_URI);
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('Successfully connected to database');
});
// parse request bodies (req.body)
app.use(bodyParser.urlencoded({ extended: true }));
router.use(function (req,res,next) {
console.log("/" + req.method);
next();
});
router.get("/",function(req,res){
res.render('index');
});
router.get('/contact',function(req,res){
res.render('contact');
});
app.use("/",router);
app.use("*",function(req,res){
res.render("404");
});
app.listen(process.env.PORT || 3000, function () {
console.log('Listening on port 3000!')
})