-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (37 loc) · 1.06 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
40
41
42
43
44
45
46
47
48
49
50
const express = require('express');
const mongoose = require('mongoose');
require('dotenv/config');
//ROUTES
const index = require('./routes/index');
const admin = require('./routes/admin');
const courses = require('./routes/courses');
const search = require('./routes/search');
//Set up express app
const app = express();
//Setup body parser for post requests
app.use(express.json());
app.use(express.urlencoded({extended :true}));
//Route middlewares
app.use('/', index);
app.use('/admin', admin);
app.use('/courses', courses);
app.use('/search', search);
//Set up a middleware
app.use(express.static('public'));
//Set up template engine
app.set('view engine', 'ejs');
//CONNECT TO DB
mongoose.connect(process.env.DB_CONNECTION, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
}).then(()=>{
console.log(`Connected to DB`)
}).catch(err=>{
console.log(`DB error ${err.message}`);
process.exit(-1)
});
app.listen(process.env.PORT || 3000, ()=>{
console.log("Listening to port");
});