-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (30 loc) · 907 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
const express = require("express")
const cors = require("cors")
const mongoose = require("mongoose")
const app = express()
app.use(cors())
require("dotenv").config()
const { PORT } = process.env || 3001
app.use(express.json())
app.use(express.static("public"))
app.listen(PORT, () => {
console.log(`STARTED PORT ${PORT}`)
})
const quizController = require("./controllers/quiz_controller.js")
app.use("/quiz", quizController)
//connect Mongo
const MONGODB_URI = process.env.MONGODB_URI
mongoose.connect(MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
})
// Error / success
mongoose.connection.on("error", err =>
console.log(
err.message,
" is MongoDB not running?/Problem with Atlas Connection?"
)
)
mongoose.connection.on("connected", () => console.log("STARTED MONGODB"))
mongoose.connection.on("disconnected", () => console.log("mongo disconnected"))