-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (22 loc) · 904 Bytes
/
Copy pathindex.js
File metadata and controls
27 lines (22 loc) · 904 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
const express = require("express")
const mongoose = require("mongoose")
const dotenv = require("dotenv")
const path = require("path")
const PORT = process.env.PORT || 5000
dotenv.config()
const app = express()
const mongoString = `mongodb+srv://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@cluster0.j4amt.mongodb.net/CyberSecWebsiteDB?retryWrites=true&w=majority`
mongoose.connect(mongoString, { useNewUrlParser: true, useUnifiedTopology: true })
mongoose.connection.on("error", function (error) {
if (process.env.NODE_ENV === "development") {
console.log(error)
}
})
mongoose.connection.on("open", function () {
console.log("Connected to MongoDB database.")
})
app.use(require("./routes/index.js"))
app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets")))
app.listen(PORT, function () {
console.log(`Express app listening on port ${PORT}`)
})