-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (24 loc) · 832 Bytes
/
app.js
File metadata and controls
33 lines (24 loc) · 832 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
require('dotenv').config()
const express = require('express')
const mongoose = require('mongoose')
const cookieParser = require('cookie-parser')
const cors = require('cors')
const errorMiddleware = require('./middlewares/error.middleware')
const app = express()
app.use(cors({ credentials: true, origin: process.env.CLIENT_URL }))
app.use(express.json())
app.use(cookieParser())
app.use(express.urlencoded({ extended: false }))
app.use('/api', require('./routes/index'))
app.use(errorMiddleware)
const bootstrap = async () => {
try {
const PORT = process.env.PORT || 8080
await mongoose.connect(process.env.MONGO_URL)
console.log('Connected to DB')
app.listen(PORT, () => console.log(`Listening on - http://localhost:${PORT}`))
} catch (error) {
console.log(`Error connecting to DB: ${error}`)
}
}
bootstrap()