forked from v-ruizh/node-todo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (26 loc) · 881 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
const express = require('express')
const mongoose = require('mongoose')
const morgan = require('morgan')
const bodyParser = require('body-parser')
const methodOverride = require('method-override')
const db = mongoose.connection
const dbConfig = require('./config/database')
const app = express()
const port = process.env.PORT || 8080
mongoose.connect(dbConfig.connection)
db.on('error', (err) => {
console.error(err.message)
mongoose.disconnect()
})
db.on('disconnected', () => {
mongoose.connect(dbConfig.connection)
})
app.use(express.static('./public'))
app.use(morgan('dev'))
app.use(bodyParser.urlencoded({ 'extended': true }))
app.use(bodyParser.json())
app.use(bodyParser.json({ type: 'application/vnd.api+json' }))
app.use(methodOverride('X-HTTP-Method-Override'))
require('./app/routes.js')(app)
app.listen(port)
console.log(`App listening on port ${port}`)