-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.js
38 lines (27 loc) · 832 Bytes
/
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
import express from 'express'
import mongoose from 'mongoose';
import cookieParser from 'cookie-parser';
import userRouter from './routes/user.js'
import blogRouter from './routes/blog.js'
import { config } from 'dotenv';
import cors from 'cors'
const app = express();
app.use(express.json())
app.use(cookieParser());
app.use(cors({
origin:[process.env.FRONTEND_URL],
methods:["GET","POST","PUT","DELETE"],
credentials:true
}))
config({
path:'./data/config.env'
})
mongoose.connect(process.env.MONGO_URL,{
dbName:"MERN_2023_YouTube"
}).then(()=>console.log("MongoDB is Connected!"))
// userRouter
app.use('/api/users',userRouter)
// blogRouter
app.use('/api/blogs',blogRouter)
// MVC = MODEL VIEWS CONTROLLS
app.listen(process.env.PORT,()=>console.log(`Server is running on Port ${process.env.PORT}`))