forked from mtsolt/SEI-Project-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (25 loc) · 878 Bytes
/
index.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
import express from 'express'
import mongoose from 'mongoose'
import { dbURI, port } from './config/environment.js'
import router from './config/router.js'
const app = express()
const startServer = async () => {
try {
await mongoose.connect(dbURI, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true })
console.log('🤩 Database has connected successfully')
//logger
app.use((req, _res, next) => {
console.log(`🚨 Incoming request: ${req.method} - ${req.url}`)
next()
})
// convert incoming JSON into JS
app.use(express.json())
//* Enable use of the router
app.use('/api', router)
//event listener
app.listen(port, () => console.log(`🚀 Express is up and running on port ${port}`))
} catch (err) {
console.log(' 💔 Something has gone wrong', err)
}
}
startServer()