-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (38 loc) · 1.1 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
42
43
44
45
46
47
48
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const morgan = require("morgan");
const mongoose = require("mongoose");
const cors = require("cors");
app.use(cors());
app.options("*", cors());
//routes
const categoriesRoutes = require("./routes/categories");
const productsRoutes = require("./routes/products");
const usersRoutes = require("./routes/users");
const ordersRoutes = require("./routes/orders");
const api = process.env.API_URL;
app.use(`${api}/categories`, categoriesRoutes);
app.use(`${api}/products`, productsRoutes);
app.use(`${api}/users`, usersRoutes);
app.use(`${api}/orders`, ordersRoutes);
//middleware
app.use(bodyParser.json());
app.use(morgan("tiny"));
app.use(express.json());
require("dotenv/config");
app.listen(3000, () => {
console.log("Server is running");
});
mongoose
.connect(process.env.CONNECTION_STRING, {
/*useNewUrlParser: true,
useUnifiedTopology: true,*/
dbName: "eshop-database",
})
.then(() => {
console.log("Database Connection is ready...");
})
.catch((err) => {
console.log(err);
});