-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
42 lines (33 loc) · 1022 Bytes
/
app.js
File metadata and controls
42 lines (33 loc) · 1022 Bytes
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
const express = require("express");
const cors = require("cors");
// Set up the express app
const app = express();
// Database Configuration
const db = require("./config/db.config");
// Test Database Connection
db.authenticate()
.then(() => {
console.log("Database connection has been established");
})
.catch((err) => {
console.error("Unable to connect to the database:", err);
});
//// Model Declarations
const User = require("./models/User");
const Product = require("./models/Product");
//// Model Relationships
User.hasMany(Product);
//// FOR DEVELOPMENT PURPOSES ONLY ////
// Synchronize Database
// db.sync({ alter: true });
// db.sync({ force: true })
// db.sync();
// Middlewares
app.use(express.json());
app.use(cors());
//Routes
app.use("/", require("./routes/default"));
app.use("/user", require("./routes/user"));
app.use("/product", require("./routes/product"));
// Start Application
app.listen(8081, console.log("Server Started -/-/-/-"));