-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (23 loc) · 802 Bytes
/
index.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
const dotenv = require('dotenv').config()
const express = require("express")
const mongoose = require("mongoose")
const cors = require('cors') //connect front and back end
const app = express()
const authController = require('./controllers/authController')
const blogController = require('./controllers/blogController')
//middleware
app.use(express.json())
app.use(express.urlencoded({extended: true}))
//routes
app.use(cors())
app.use('/auth', authController)
app.use('/blog', blogController)
// Server Listener
const PORT = process.env.PORT || 3001;
//conncect db
mongoose.connect(process.env.MONGO_URL)
.then(()=> {
console.log("Database Connected")
app.listen(PORT, () => console.log(`Now Listening on port ${PORT}`));
})
.catch((error)=> console.log("Database not connected",error))