-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
36 lines (26 loc) · 828 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
34
35
36
import express from 'express'
import { port } from './config/environment.js'
import logger from './lib/logger.js'
import connectToDatabase from './lib/connectToDB.js'
import router from './config/router.js'
import errorHandler from './lib/errorHandler.js'
const app = express()
async function startServer() {
try {
await connectToDatabase()
console.log('Database has connected')
//*Makes req.body available
app.use(express.json())
//*Logger logs each request to the console
app.use(logger)
//*Routes all routes
app.use('/api', router)
//*Handles errors
app.use(errorHandler)
app.listen(port, () => console.log(`🤖 Up and running on port ${port}`))
} catch (err) {
console.log('🤖 Something went wrong starting the App')
console.log(err)
}
}
startServer()