-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
42 lines (28 loc) · 986 Bytes
/
server.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
const express=require('express')
const dotenv=require('dotenv')
const morgan=require('morgan')
const bodyparser=require('body-parser')
const path=require('path')
const connectDB=require('./server/database/connection')
const app=express()
const publicDirectoryPath=path.join(__dirname,'./assets')
dotenv.config({path:'config.env'})
const port=process.env.PORT || 8080
const hostname='0.0.0.0'
//log the requests
app.use(morgan('tiny'))
//mongodb connection
connectDB()
//parse to body-parser
app.use(bodyparser.urlencoded({extended:true}))
app.set('view engine','hbs')
//loading assets
// app.use('/css',express.static(path.resolve(__dirname,'assets/css')))
// app.use('/img',express.static(path.resolve(__dirname,'assets/img')))
// app.use('/js',express.static(path.resolve(__dirname,'assets/js')))
app.use(express.static('assets'))
//load routers
app.use('/',require('./server/routes/router'))
app.listen(port,hostname,()=>{
console.log('Server running on '+port)
})