-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (35 loc) · 1.07 KB
/
index.js
File metadata and controls
46 lines (35 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
35
36
37
38
39
40
41
42
43
44
45
46
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const sequelize = require("./config/db");
const httpStatusText = require("./utils/httpStatusText");
const PORT = process.env.PORT || 8080;
const app = express();
app.use(cors());
app.use(express.json());
const projectsRouter = require("./routes/projects.route");
app.use("/api/projects", projectsRouter);
app.all("*", (_req, res, _next) => {
return res.status(404).json({
status: httpStatusText.FAIL,
message: "this resource is not available",
});
});
// global error handler
app.use((error, _req, res, _next) => {
res.status(error.statusCode || 500).json({
status: error.statusText || httpStatusText.ERROR,
message: error.message,
code: error.statusCode || 500,
data: null,
});
});
app.listen(PORT, async () => {
console.log(`listening on port ${PORT}`);
try {
await sequelize.authenticate();
console.log("Connection has been established successfully.");
} catch (error) {
console.error("Unable to connect to the database:", error);
}
});