-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (47 loc) · 1.55 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
// importing requirements
const express = require("express")
const mongo = require('mongoose')
const cookieParser = require("cookie-parser")
//Routers
const AuthenticationRoute = require('./routers/authentication.js')
const IndexRoute = require('./routers/index_news.js')
const UserRoute = require('./routers/user.js')
const APIRoute = require('./routers/api.js')
//--------------------------------------------------------//
//creating a server
const app = express()
// register view engine as ejs
app.set('view engine', 'ejs')
// cookie praser for access the browser cookie
app.use(cookieParser())
// static file
app.use(express.static('public'))
app.use(express.json())
app.use(express.urlencoded({
extended: true
}))
// mongodb uri to connect with database
const ConnectMongoDB = "mongodb+srv://Binary-Beast-01:[email protected]/?retryWrites=true&w=majority"
const PORT = process.env.PORT || 8888
//mongo db connection
mongo.connect(ConnectMongoDB, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then((res) => {
console.log('db Connection................ok')
//listen for a server request
app.listen(PORT, () => {
console.log('Main Server.................ok')
});
}).catch((err) => console.log(err))
// Routering operations
app.use('/auth', AuthenticationRoute) // Authentication Route
app.use('/', IndexRoute) //Index Route
app.use('/user', UserRoute) //User Route
app.use('/api', APIRoute) //API Route
// 404 Page
app.use((req, res) => {
res.status(404).render('404', {
msg: '404 Page Not Found'
})
});