-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (37 loc) · 1.24 KB
/
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
39
40
41
42
43
import cors from 'cors'
import dotenv from 'dotenv'
import express from 'express'
import mongoose from 'mongoose'
import bodyParser from 'body-parser'
import cookieParser from 'cookie-parser'
import userRouter from './routing/userRoutes.js'
import blogRouter from './routing/blogRoutes.js'
import commentRouter from './routing/commentRoutes.js'
const app = express()
dotenv.config()
const PORT = 5500
const URI = `mongodb+srv://${process.env.MONGODB_USER}:${process.env.MONGODB_PASS}@blog.ufnd36v.mongodb.net/?retryWrites=true&w=majority`
// ----------------------------------------------------------------
// Middleware
// ----------------------------------------------------------------
app.use(express.json())
app.use(
cors({
origin: '*',
})
)
app.use(cookieParser())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use('/users', userRouter)
app.use('/blogs', blogRouter)
app.use('/comments', commentRouter)
// ----------------------------------------------------------------
// Connections
// ----------------------------------------------------------------
mongoose.connect(URI).then(() => {
app.listen(PORT, () => {
console.log('Connected to Database')
console.log(`App listening on PORT ${PORT}`)
})
})