-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (29 loc) · 1.07 KB
/
Copy pathapp.js
File metadata and controls
34 lines (29 loc) · 1.07 KB
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 app = express();
const connectDB = require(`./db/connect`);
const tasks = require(`./routes/tasks`);
const notFound = require(`./middleware/not-found`);
// ------------------- MIDDLEWARE ----------------------------
app.use(express.static(`./public`));
app.use(express.json());
// ------------------ IP and PORT ----------------------------
const hostAdd = process.env.HOST_ADDRESS;
const port = process.env.PORT;
// ----------------------- API -------------------------------
app.use(`/api/v1/tasks/`, tasks);
app.use(notFound)
// ---------------------- CONNECT TO DB ----------------------
const start = async () => {
try {
await connectDB()
.then(() => console.log("Successfully connected to DB"))
.catch((error) => console.log(error));
// ---------------------- LISTEN -----------------------------
app.listen(port, hostAdd, () => {
console.log(`The server is listening on http://${hostAdd}:${port}`);
});
} catch (error) {
console.log(error);
}
};
start();