-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (31 loc) · 952 Bytes
/
Copy pathapp.js
File metadata and controls
40 lines (31 loc) · 952 Bytes
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
require("dotenv").config();
const cors = require("cors");
const express = require("express");
const mongoose = require("mongoose");
const thumbRoutes = require("./routes/thumbRoute");
const productRoutes = require("./routes/productRoute");
const commentRoutes = require("./routes/commentRoute");
const DB_URL = process.env.DATABASE_URL;
const app = express();
const port = process.env.PORT;
// Apply CORS middleware before defining routes or using other middleware
app.use(cors());
mongoose.connect(DB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const db = mongoose.connection;
db.on("error", (err) => {
console.log(err);
});
db.once("connected", () => {
console.log("DB CONNECTED");
});
app.use(express.json());
app.use("/thumb", thumbRoutes);
app.use("/product", productRoutes);
app.use("/comments", commentRoutes);
app.listen(port, () => {
console.log(`server running in port: ${port}`);
});
module.exports = app;