-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (25 loc) · 801 Bytes
/
index.js
File metadata and controls
30 lines (25 loc) · 801 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
28
29
30
//dependencies
require("dotenv").config()
const express = require("express")
const mongoose = require("mongoose")
const bodyParser = require("body-parser")
const path = require("path")
const morgan = require("morgan")
const app = express()
// middleware
app.use(bodyParser.json())
app.use(morgan("dev"))
app.use(express.static(path.join(__dirname, "static")))
// routes
app.use("/api/v1", require("./routes"))
app.get("/docs", (req, res) => {
res.sendFile(path.join(__dirname, "static", "docs", "index.html"))
})
// connect to database
mongoose.connect(process.env.MONGODB_URI, (err) => {
if (err) throw err
console.log(`Connected to MongoDB on ${process.env.MONGODB_URI}`)
})
app.listen(process.env.PORT, () => {
console.log(`Connected to Server on port ${process.env.PORT}`)
})