-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (28 loc) · 874 Bytes
/
server.js
File metadata and controls
35 lines (28 loc) · 874 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
import express from "express";
import cors from "cors";
import mongoose from "mongoose";
import allBrands from "./controller/brands.js";
import allProducts from "./controller/products.js";
// app config
const app = express();
const port = process.env.PORT || 8000;
// middlewares
app.use(express.json());
app.use(cors());
// DB config
const mongoURI =
"mongodb+srv://admin:HVKRGjoOa3DwFsaz@cluster0.mdubn.mongodb.net/b2cDB?retryWrites=true&w=majority";
mongoose.connect(mongoURI, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
});
mongoose.connection.once("open", () => {
console.log("DB Connected");
});
// api Routes
app.get("/", (req, res) => res.status(200).send("Hello World"));
app.use("/brands", allBrands);
app.use("/products", allProducts);
// listen
app.listen(port, () => console.log(`listening on localhost:${port}`));