forked from cjhird/AMDB-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (28 loc) · 833 Bytes
/
server.js
File metadata and controls
33 lines (28 loc) · 833 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
import express from 'express'
import connectToDb from './utils/db.js'
import logger from './middleware/logger.js'
import router from './router.js'
import CONSTS from './consts.js'
import cors from 'cors'
import errorHandler from './middleware/errorHandler.js'
import dotenv from 'dotenv'
const startServer = async () => {
const app = express()
dotenv.config()
app.use(cors())
app.use(express.json())
app.use(logger)
app.use(router)
app.use(errorHandler)
// ! CATCH
app.use((req, res, next) => {
console.log('request cant be met', req.url, req.method)
return res.status(404).send('404 - Required endpoint not found.')
})
await connectToDb()
console.log('Database connected')
app.listen(CONSTS.PORT, () => {
console.log(`🤯Server running on port ${CONSTS.PORT}🤯`)
})
}
startServer()