-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
48 lines (41 loc) · 1.22 KB
/
main.js
File metadata and controls
48 lines (41 loc) · 1.22 KB
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
const express = require("express");
const dotenv = require("dotenv");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const errorHandler = require("./middleware/errorHandler");
const tryCatch = require("./utils/tryCatch");
const AppError = require("./utils/AppError");
const cookieParser = require("cookie-parser");
const path = require("path");
const route = require("./routes/route");
dotenv.config();
const app = express();
const PORT = 5002 || process.env.PORT;
// serving static files
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.use(express.static(__dirname + "/public"));
// Body-parser middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cookieParser());
// connecting db
mongoose.set("strictQuery", false);
mongoose.connect(process.env.URI, () => {
console.log("Db connected");
});
console.log(mongoose.connection.readyState);
const getUser = () => undefined;
app.get(
"/",
tryCatch(async (req, res, next) => {
res.render("landing");
})
);
//middleware
app.use(errorHandler);
app.use(route);
// listining port
app.listen(PORT, (req, res) => {
console.log(`server is listining on port ${PORT}`);
});