-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (37 loc) · 1014 Bytes
/
app.js
File metadata and controls
44 lines (37 loc) · 1014 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
43
44
const express = require("express");
const config = require("config");
const path = require("path");
const mongoose = require("mongoose");
const app = express();
app.use(express.static(path.join(__dirname, "frontend/build")));
app.use(
express.json({
extended: true,
})
);
app.use("/api/auth", require("./routes/auth.routes.js"));
app.use("/api/check", require("./routes/check.routes.js"));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "frontend/build/index.html"));
});
const PORT = process.env.PORT || 5000;
const start = async () => {
try {
await mongoose.connect(
config.get("mongoUri"),
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
},
() => console.log(`DB has been connected successfully`)
);
app.listen(PORT, () =>
console.log(`App has been started on port ${PORT}...`)
);
} catch (e) {
console.log(`Server Error: ${e.message}`);
process.exit(1);
}
};
start();