forked from poonam3100/CRUD-project-Assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (33 loc) · 979 Bytes
/
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
39
const express = require("express");
const app = express();
const _PORT = process.env.PORT || 3000;
const cors = require("cors");
const morgan = require("morgan");
const dotenv = require('dotenv');
dotenv.config();
app.use(morgan("default"));
var corsOptions = {
origin: "*",
};
app.use(cors(corsOptions));
// parse requests of content-type - application/json
app.use(express.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true }));
app.get("/index", (req, res, next) => {
res.sendFile(`${__dirname}/index.html`);
});
app.get("/", (req, res, next) => {
return res.status(200).json({
status: true,
message: "MY CRUD Application",
});
});
const db = require("./models");
db.sequelize.sync({ alter: true }).then(() => {
console.log("Drop and re-sync db.");
});
require("./routes/users.routes")(app);
app.listen(_PORT, () => {
console.log(`App is UP and Running at PORT: ${_PORT}`);
});