-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
30 lines (27 loc) · 809 Bytes
/
app.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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const myRoutes = require("./routes/myRoutes");
const cookieParser = require("cookie-parser");
const { checkUser } = require("./middleware/authMiddleware");
require('dotenv').config();
// middleware
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(express.json());
app.use(cookieParser());
// Connect to MongoDB
mongoose.connect(process.env.MONGODB_URI)
.then(result => {
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`App is listening on port ${PORT}.`);
})
})
.catch(err => {
console.log(err)
})
// Pass User Object to all Views
app.get("*", checkUser);
// Routes Middleware
app.use(myRoutes);