-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (31 loc) · 1.01 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
require("dotenv").config();
require("express-async-errors");
const mongoose = require("mongoose");
const express = require("express");
const cookieParser = require("cookie-parser");
const mainRoutes = require("./routes/mainRoutes");
const adminRoutes = require("./routes/adminRoutes");
const authRoutes = require("./routes/authRoutes");
const { notFound, errorHandler } = require("./middleware/errorHandler");
const app = express();
app.set("view engine", "ejs");
app.use(express.json());
app.use(express.static("public"));
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use("/uploads", express.static("uploads"));
app.use("/", mainRoutes);
app.use("/admin", adminRoutes);
app.use("/auth", authRoutes);
app.use(errorHandler);
app.use(notFound);
const PORT = process.env.PORT || 5000;
const start = async () => {
try {
await mongoose.connect(process.env.URI);
app.listen(PORT, console.log(`server listening in port: ${PORT}`));
} catch (error) {
console.log(error);
}
};
start();