-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (26 loc) · 798 Bytes
/
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
const express = require("express");
const mongoose = require("mongoose");
const Product = require("./models/product.model.js");
const productRoute = require("./routes/product.route.js");
const app = express();
// middleware
app.use(express.json());
app.use(express.urlencoded({extended: false}));
// routes
app.use("/api/products", productRoute);
app.get("/", (req, res) => {
res.send("Hello from Node API Server Updated");
});
mongoose
.connect(
"mongodb+srv://haris2iftikhar:GClTzr15XhkjvN6k@backenddb.nrurtot.mongodb.net/Node-API?retryWrites=true&w=majority"
)
.then(() => {
console.log("Connected to database!");
app.listen(3000, () => {
console.log("Server is running on port 3000");
});
})
.catch(() => {
console.log("Connection failed!");
});