-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (38 loc) · 1.18 KB
/
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
40
41
42
43
44
45
46
const express = require("express");
const app = express();
const cors = require("cors");
const bodyParser = require("body-parser");
const { DataSource } = require("typeorm");
//port
const port = process.env.PORT || 5000;
//config
const corsOptions = require("./config/corsConfig");
const dbConfig = require("./config/database");
//Routes Import
const userRoutes = require("./controllers/usersController");
const productRoutes = require("./controllers/productController");
//Cors and BodyParser
app.use(cors(corsOptions));
app.use(bodyParser.json());
//Routes
app.use("/", userRoutes);
app.use("/", productRoutes);
//DB
const Database = new DataSource({
type: dbConfig.type,
host: dbConfig.host,
port: dbConfig.port,
username: dbConfig.username,
password: dbConfig.password,
database: dbConfig.database,
entities: dbConfig.entities,
synchronize: dbConfig.synchronize,
});
Database.initialize()
.then((response) => {
console.log("Database PostgresQL Working on Port 5432");
})
.catch((error) => {
console.log(error, `error occured connectiong ${dbConfig.type}`);
});
app.listen(process.env.PORT, () => console.log(`Running on port ${port}`));