-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (30 loc) · 813 Bytes
/
app.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
require('dotenv').config()
//errors
require('express-async-errors')
const express = require('express')
const app = express()
//router
const productsRouter = require('./routes/products')
//DB
const mongoDB = require('./db/connect')
//not found
const notFoundMiddleWare = require('./middleware/not-found')
//error middleWare
const errorMiddleWare = require('./middleware/error-handler')
//use json
app.use(express.json())
//route
app.use('/api/v1/products', productsRouter)
app.use(notFoundMiddleWare)
app.use(errorMiddleWare)
const port = process.env.PORT || 3000
const spinServer = async ()=>{
try {
//connectDB
await mongoDB(process.env.MONGO_URI)
app.listen(port, console.log(`Server is listening on port ${port}...`))
} catch (error) {
console.log(error)
}
}
spinServer()