-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (27 loc) · 783 Bytes
/
app.js
File metadata and controls
34 lines (27 loc) · 783 Bytes
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 app = express()
const bodyParser = require('body-parser')
const morgan = require('morgan')
const db = require('./db/db')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(morgan('dev'))
app.use(function (err, req, res, next) {
console.error(err.stack)
res.status(500).send('Something broke!')
})
const init = async () => {
if (require.main === module) {
//will only run when run with npm start and not with npm test to avoid db syncing in multiple threads when running tests
try {
await db.sync()
app.listen(3000, () => {
console.log('Server is listening on port 3000!')
})
} catch (err) {
console.error(err)
}
}
}
init()
module.exports = app