-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (29 loc) · 1016 Bytes
/
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
import express from 'express'
import path from 'path'
import dotenv from 'dotenv'
import morgan from 'morgan'
import bodyParser from 'body-parser'
import connectDB from './app/server/database/connection.js'
import routes from "./app/server/routes/routes.js";
const app = express()
const __dirname = path.resolve();
dotenv.config({path: 'config.env'})
const PORT = process.env.PORT || 8080
// Log request
app.use(morgan(':method :url :status :res[content-length] - :response-time ms'))
//Database connection
connectDB()
// Parse request to body-parser
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())
// Set view engine
app.set('view engine', 'pug')
app.set('views', path.resolve(__dirname, 'app/views'))
// Load assets
app.use(express.static(path.join(__dirname, 'app/assets')))
app.use(express.static(path.join(__dirname,'public')))
// Load routers
app.use('/', routes)
app.listen(PORT, () => {
console.log(`Server running on ${PORT}`)
})