-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
33 lines (25 loc) · 835 Bytes
/
app.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
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const routes = require("./routes");
const dotenv = require("dotenv");
const path = require("path");
const app = express();
dotenv.config();
app.use(bodyParser.json());
const PORT = process.env.PORT || 5000;
mongoose
.connect(process.env.DATABASE_URL, { useNewUrlParser: true })
.then(success => {
console.log("Db connected");
})
.catch(error => {
console.log("error connecting to the database", error);
});
app.use("/", routes);
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, "build")));
app.get("/*", function(req, res) {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
app.listen(PORT, () => console.log(`app is running on port ${PORT}`));