-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (25 loc) · 971 Bytes
/
index.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
const express = require("express");
const handlebars = require("express-handlebars");
const mongoose = require("mongoose");
const cookieParser = require("cookie-parser");
const routes = require("./src/routes");
const { authMiddleware } = require("./src/middleware/authMiddleware");
const app = express();
const port = 3000;
app.use(express.static("src/public"));
app.use(express.urlencoded({ extended: false}));
app.use(cookieParser());
app.use(authMiddleware);
app.engine("hbs", handlebars.engine({
extname: "hbs",
}));
app.set("view engine", "hbs");
app.set("views", "src/views");
app.use(routes);
mongoose.connect("mongodb://localhost:27017/friendly-world");
mongoose.connection.on("connected", () => console.log("DB is connected"));
mongoose.connection.on("disconnected", () => console.log("DB is disconnected"));
mongoose.connection.on("error", (err) => console.log(err));
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});