-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (27 loc) · 867 Bytes
/
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
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const db_conf = require("./src/configs/db_conf.js");
// DB connection
mongoose.connect(db_conf.url);
const db = mongoose.connection;
db.on("error", (err) => {
console.log("Error connecting to DB", err);
});
db.once("connected", () => {
console.log("DB connected");
});
// App hosting
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const backend_routes = require("./src/routes/backend_routes.js");
const frontend_routes = require("./src/routes/frontend_routes.js");
app.use("/api", backend_routes);
app.use("/", frontend_routes);
// App listening
const port = process.env.PORT || 3000;
app.listen(port, "0.0.0.0", () => {
console.log(`App listening at http://localhost:${port}`);
});