-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (27 loc) · 770 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
35
36
37
38
39
const express = require("express");
const cors = require("cors");
require("dotenv").config();
const db = require("./src/database");
const Contact = require("./src/models/contact");
//routes imports
const contactsRoute = require("./src/routes/contacts");
const app = express();
//middleware
app.use(express.json());
app.use(cors());
//routes
app.use("/api/contacts", contactsRoute);
const port = process.env.PORT || 4000;
const init = async () => {
try {
await db.authenticate();
console.log("Connection has been established successfully.");
await Contact.sync();
app.listen(port, () => {
console.log("listen on port " + port);
});
} catch (error) {
console.error("Unable to connect to the database:", error);
}
};
init();