-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (40 loc) · 1.12 KB
/
index.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const morgan = require("morgan");
const cors = require("cors");
//const path = require("path");
//var bodyParser = require("body-parser");
/*const port = process.env.PORT || 3000;
const publicPath = path.join(__dirname, "..", "public");
app.use(express.static(publicPath));
app.listen(port, () => {
console.log(`Server is up on port ${port}!`);
});
*/
if (process.env.NODE_ENV === "production") {
app.use(express.static("frontend/build"));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "frontend", "build", "index.html"));
});
}
app.use(cors());
app.use(morgan("dev"));
app.use(express.json());
const infoRouter = require("./router");
app.use("/info", infoRouter);
const PORT = 5000;
app.listen(PORT, () => {
console.log("server started on port 5000");
});
//FQx4KXLFUuYu9m6l
const uri = process.env.mongodb || "mongodb://localhost/mybooks";
mongoose.connect(
uri,
{ useNewUrlParser: true, useUnifiedTopology: true },
(err) => {
if (!err) {
console.log("db connection successfull");
}
}
);