-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
71 lines (45 loc) · 1.29 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require('express');
const moongose = require('mongoose');
const app = express();
const { MongoClient, ServerApiVersion } = require('mongodb');
const dotenv = require('dotenv');
const PORT = process.env.PORT || 5000;
dotenv.config()
const MONGODB_URI = process.env.MONGODB_URI_URL;
const setMiddleware = require('./middleware/middlewares')
const setRoutes = require('./routes/routes');
//setup view engine
app.set('view engine', 'ejs');
app.set('views', 'views');
//useing MiddlleWare from MiddleWare Directory
setMiddleware(app)
//useing routes from routes Directory
setRoutes(app);
app.use((req, res, next) => {
let error = new Error('404 Page Not Found')
error.status = 404
next(error)
})
app.use((error, req, res, next) => {
if (error.status === 404) {
return res.render('pages/error/404.ejs', {
flashMessage: {},
title: '404 Not Found'
})
}
console.log(error);
res.render('pages/error/500', {
flashMessage: {}
})
})
//connection......
moongose.connect(MONGODB_URI, {
useNewUrlParser: true
})
.then(() => {
console.log(('Database connected'));
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
})
.catch(e => {
console.log(e);
})