-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (33 loc) · 904 Bytes
/
server.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
40
41
42
43
44
45
import express from "express"
import cors from "cors"
const app = express()
import routes from "./routes/index.js";
import { sequelize } from "./model/index.js";
// const db = import('./model') ? create new models according to the requirements
import errorHandler from "./middleware/errorHandler.js"
const cors_setting = {
origin: "*",
}
// Sync the database
sequelize
.sync({ force: false })
.then(() => {
console.log("Database Synced")
})
.catch((err) => {
console.log("Database Sync Failed ", err)
})
// Server Config
app.use(cors(cors_setting))
app.use(express.json())
// route home - server starting server
app.get("/", (req, res) => {
return res.send("Server Running!!")
})
// import api routes
app.use("/api", routes);
app.use(errorHandler)
const PORT = process.env.PORT || 5000
app.listen(PORT, () => {
console.log("Server Running http://localhost:", PORT)
})