-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (29 loc) · 1.16 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
const express = require("express");
const errors = require("./middleware/errors.js");
const swaggerUi = require("swagger-ui-express"), swaggerDocument = require("./swagger.json");
const database = require("./config/db.config.js");
const app = express();
setUpDatabase().then(
() => {
console.log("Database is ready");
app.use(express.json());
app.use("/api", require("./routes/app.routes"));
app.use(errors.errorHandler);
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.listen(process.env.port || 3000, function () {
console.log("Ready at localhost:3000/api/*");
});
}).catch((error) => {
console.log("Database is not ready", error);
});
async function setUpDatabase() {
try {
await database.sequelize.authenticate();
console.log("Database is authenticated");
const result = await database.sequelize.sync();
console.log("Database is synced", result.models);
console.log('Connection has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
}