generated from wecode-bootcamp-korea/backend-2nd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (28 loc) · 846 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
34
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const appDataSource = require("./api/models/dataSource");
const { globalErrorHandler } = require("./api/utils/error");
const routes = require("./api/routes");
const PORT = process.env.PORT;
const app = express();
app.use(express.json());
app.use(cors());
app.use(morgan("combined"));
app.use(routes);
app.use(globalErrorHandler);
app.get("/ping", (req, res) => {
res.json({ message: "pong" });
});
app.listen(PORT, async () => {
await appDataSource
.initialize()
.then(() => {
console.log("Data Source has been initialized!");
})
.catch((error) => {
console.error("Error during Data Source initialized", error);
});
console.log(`Listening to request on port: ${PORT}`);
});