-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (36 loc) · 1.08 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
40
41
42
43
44
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const userRouter = require("./routes/user");
const authRouter = require("./routes/auth");
const productRouter = require("./routes/product");
const cartRouter = require("./routes/cart");
const orderRouter = require("./routes/order");
dotenv.config();
mongoose
.connect(process.env.MONGO_URL)
.then(() => {
console.log("connect to mongo");
})
.catch((err) => {
console.log(err);
});
app.use(express.json());
//how next() work
// app.get("/", function(httpRequest, httpResponse, next){
// httpResponse.write("Hello");
// next();
// });
// app.get("/", function(httpRequest, httpResponse, next){
// httpResponse.write(" World !!!");
// httpResponse.end();
// });
app.use("/api/user", userRouter);
app.use("/api/auth", authRouter);
app.use("/api/products", productRouter);
app.use("/api/carts", cartRouter);
app.use("/api/orders", orderRouter);
app.listen(process.env.PORT || 5000, () => {
console.log("working!")
});