forked from emilieallen/project-3-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (25 loc) · 845 Bytes
/
server.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
37
38
import { PORT } from "./config/environment.js"
import router from "./views/router.js"
import express from "express"
import { connectToDb } from "./db/helpers.js"
import logger from "./middleware/logger.js"
import errorHandler from "./middleware/errorHandler.js"
import cors from "cors"
import dotenv from "dotenv"
// ? Setting up express ready to use
async function startServer() {
const app = express()
dotenv.config()
const PORT = process.env.PORT ? process.env.PORT : 4000
app.use(cors())
// ! Tell express it's a JSON API
app.use(express.json())
// ? Tell express about our router
app.use(logger)
app.use(router)
app.use(errorHandler)
await connectToDb()
// ? Listen on a port
app.listen(PORT, () => console.log(`Express server running on port ${PORT}`))
}
startServer()