-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
42 lines (34 loc) · 1019 Bytes
/
app.js
File metadata and controls
42 lines (34 loc) · 1019 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
31
32
33
34
35
36
37
38
39
40
41
42
const express = require('express');
const app = express()
const port = process.env.port || 5000;
const mongoose = require("mongoose");
const { mongoUrl } = require("./keys");
const cors = require("cors");
const path = require("path")
app.use(cors())
require('./models/model')
require('./models/post')
app.use(express.json())
app.use(require("./routes/auth"))
app.use(require("./routes/createPost"))
app.use(require("./routes/user"))
mongoose.connect(mongoUrl);
mongoose.connection.on("connected", () => {
console.log("successfully connected to mongo")
})
mongoose.connection.on("error", () => {
console.log("not connected to mongodb")
})
// serving the frontend
app.use(express.static(path.join(__dirname, "./frontend/build")))
app.get("*", (req, res) => {
res.sendFile(
path.join(__dirname, "./frontend/build/index.html"),
function (err) {
res.status(500).send(err)
}
)
})
app.listen(port, () => {
console.log("server is running on port" + " " + port)
})