-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (28 loc) · 789 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
const express = require("express");
const mongoose = require("mongoose");
const Product = require("./models/product.model.js");
const app = express();
const productRoute = require("./routes/product.route.js");
//Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
//Routes
app.use("/api/products", productRoute);
app.get("/", (req, res) => {
res.send("Hello World");
});
//
const pw = "ctcm14237";
mongoose
.connect(
`mongodb+srv://huutin1712:${pw}@backend.ew5bc.mongodb.net/node-api?retryWrites=true&w=majority&appName=Backend`
)
.then(() => {
console.log("Conneted to Database!");
app.listen(3000, () => {
console.log("Server is running");
});
})
.catch(() => {
console.log("Failed!");
});