-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
36 lines (26 loc) · 804 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
const express = require('express')
const bodyParser = require('body-parser')
const path = require('path')
const mongoose = require('mongoose')
const db = require('./config/database')
const api = require('./server/routes/api')
const port = process.env.PORT || 3000
const app = express()
console.log(db.database)
mongoose.Promise = global.Promise
mongoose.connect(db.database, (err) => {
if (err) {
console.error('Error! ' + err)
}
})
console.log(__dirname)
app.use(express.static(path.join(__dirname, 'public')))
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())
app.use('/api', api)
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public/index.html'))
})
app.listen(port, () => {
console.log('Server running on port ' + port)
})