-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (23 loc) · 729 Bytes
/
Copy pathserver.js
File metadata and controls
37 lines (23 loc) · 729 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
36
37
const express = require("express");
const path = require("path")
const app = express();
const cors = require("cors");
try {
var mongoose = require("mongoose");
} catch(e) {
console.log(e)
};
require("dotenv").config();
const productRouter = require("./Backend/ShoppingCart");
// Body parser middleware
app.use(express.json());
app.use(express.urlencoded({extended: false}))
app.use(cors())
app.use("/products", productRouter);
// static folder
app.use(express.static(path.join(__dirname, "public")))
mongoose.connect(process.env.MONGO_URL, { useNewUrlParser: true, useUnifiedTopology: true })
.then(res => {console.log("success")})
.catch(res => {console.error("error")})
const port = 8000;
app.listen(port)