-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (32 loc) · 1.31 KB
/
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
40
41
const express = require("express");
const cors = require("cors");
const app = express();
const corsOptions = {
origin: "http://localhost:8090"
}
app.use(cors(corsOptions));
//parse request of content-type - - application/json
app.use(express.json());
//parse request of content-type - - application/ww-form-url-encoded
app.use(express.urlencoded({ extended: true }));
//default app port calling response
app.get("/", (req, res) => {
res.json({ message: "Welcome To our Node JS Express Js using Rest API with Sequelze ORM and MySQL DB Connection" });
});
const PORT = process.env.PORT || 8090;
app.listen(PORT, () => {
console.log("\nYou NodeJS Express Server App is running on the PORT " + PORT + "\n");
});
// set port, listen for requests
require("./app/routes/routes")(app);
//build/establish db conection by calling index.js file
var db = require("./app/models");
//let the nodejs create tables according to the models.
//comment this if you do not want to make tables empty on reRunning the APP in CMD.
//This code on runnig the app will create tabees from models and delete all data if exist.
//if you comment this line, you have to create tables in database.
// db.sequelize.sync({ force: true }).then(() => {
// console.log("Db synced");
// }).catch(() => {
// console.log("Fail to synce DB");
// });