-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (25 loc) · 734 Bytes
/
server.js
File metadata and controls
29 lines (25 loc) · 734 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
import express, { urlencoded } from "express"
import mongoose from "mongoose"
import { APP_PORT, DB_URL } from './config'
const mainRouter = require('./routes/index')
const errorHandlerMiddleWare = require('./middlewares/errorHandler.js')
const app = express()
//db
async function dbConnection() {
try {
await mongoose.connect(DB_URL)
console.log("DB connected")
} catch (err) {
throw err
}
}
dbConnection().then(()=>{
app.listen(APP_PORT, () => {
console.log(`server started at ${APP_PORT}`)
})
})
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.use('/api', mainRouter)
app.use('/uploads', express.static('uploads'))
app.use(errorHandlerMiddleWare)