-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
51 lines (43 loc) · 1.36 KB
/
server.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
45
46
47
48
49
50
51
const express = require("express");
const mongoose = require("mongoose");
const ejs = require("ejs");
const expressLayouts = require("express-ejs-layouts");
const cookieParser = require("cookie-parser");
require("dotenv").config();
const app = express();
app.use(cookieParser());
//Mongoose Connection
const database = async () => {
await mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("MongoDB Connected"))
.catch((err) => console.log(err));
};
//Express Static
app.use(express.static("public"));
app.use("/css", express.static(__dirname + "/public/css/"));
app.use("/js", express.static(__dirname + "/public/js/"));
app.use("/img", express.static(__dirname + "/public/img/"));
app.use("/assets", express.static(__dirname + "/assets/"));
//Express Parser
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
//Ejs
app.use(expressLayouts);
app.set("view engine", "ejs");
//Routes
app.use("/", require("./routes/index"));
app.use("/user", require("./routes/users"));
app.use("/menu", require("./routes/menu"));
app.use("/cart", require("./routes/cart"));
app.use("/orders", require("./routes/orders"));
//Listen
database().then(() => {
app.listen(
process.env.PORT,
console.log(`Server is running on http://localhost:${process.env.PORT}`)
);
});