-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (33 loc) · 1.05 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
const dotenv = require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const app = express();
const port = process.env.PORT || 3000;
//imports
const productRoute = require("./routes/product.route.js");
const inventoryRoute = require("./routes/inventory.route.js");
const orderRoute = require("./routes/order.route.js");
//middleware
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
//routing
app.use("/products", productRoute);
app.use("/inventory", inventoryRoute);
app.use("/order", orderRoute);
app.get("/", (req, res) => {
res.send("Hello, welcome to the FTG backend!");
});
mongoose
.connect(
`mongodb+srv://${process.env.MONGO_USERNAME}:${process.env.MONGO_PASSWORD}@backendapi.glg1xdr.mongodb.net/?retryWrites=true&w=majority&appName=BackendAPI`
)
.then(() => {
console.log("DB connected");
app.listen(`${port}`, () => {
console.log("Listening on port 3000");
});
})
.catch(() => {
console.log("Failed to connect to DB");
});
module.exports = app;