-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
49 lines (40 loc) · 1.25 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
if (process.env.NODE_ENV !== "production") {
require("dotenv").config();
}
const express = require("express");
const ejsMate = require("ejs-mate");
const methodOverride = require("method-override");
const { db } = require("./configs/dbConfig");
const session = require("./configs/sessionConfig");
const passport = require("./configs/passportConfig");
const flash = require("./configs/flashConfig");
const app = express();
// DB Connection
db.on("error", console.error.bind(console, "Connection Error:"));
db.once("open", () => {
console.log("DATABASE CONNECTED!!");
});
// Body-parsers and Static files
app.use(methodOverride("_method"));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(express.static(__dirname + "/public"));
// View Engine
app.set("views", __dirname + "/views");
app.set("view engine", "ejs");
app.engine("ejs", ejsMate);
// Configs
session(app);
passport(app);
flash(app);
// Routes
app.use("/", require("./routes/index"));
app.use("/auth", require("./routes/auth"));
app.use("/resources", require("./routes/resources"));
// Api Routes
app.use("/api", require("./api/routes/index"));
// Start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});