-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (30 loc) · 859 Bytes
/
index.js
File metadata and controls
39 lines (30 loc) · 859 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
34
35
36
37
38
39
import express from 'express'
import cookieParser from 'cookie-parser'
import { config } from 'dotenv'
import mongoose from 'mongoose'
import cors from 'cors'
import router from './src/router/index.js'
import errorMiddleware from './src/middleware/errorMiddleware.js'
config() //read configuration from .env file
const PORT = process.env.PORT || 5000;
const app = express()
app.use(express.json());
app.use(cookieParser());
app.use(cors({
credentials: true,
origin: process.env.CLIENT_URL
}));
app.use('/api', router)
app.use(errorMiddleware)
const startServer = async () => {
try{
await mongoose.connect(process.env.MONGO_CONNECTION_STRING, {
useUnifiedTopology: true,
useNewUrlParser: true,
})
app.listen(PORT, () => console.log(`Server started on port ${PORT}`))
}catch (e) {
console.log(e)
}
}
startServer()