-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (40 loc) · 1.64 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
50
51
52
53
//----------------------------------------------------------------//
//Main Entry Point of the Express Server App//
//----------------------------------------------------------------//
const express = require("express");
const port = process.env.PORT || 8000;
const app = express();
//Require Module Path for Directory
const path = require("path");
//Requires the index.js - Route File, from the Routes Folder
const route = require("./routes/index.js");
const expressLayouts = require("express-ejs-layouts");
const db = require("./config/mongoose.js");
const cors = require("cors");
const dotenv = require("dotenv").config();
//Use the Cors Module
app.use(cors());
//Middleware - Express App uses Static Files in the Assets Folder
app.use(express.static("./assets"));
//Middleware - Express App uses expressLayouts to tell that the views which are going to be rendered belongs to some layout
app.use(expressLayouts);
//Set Up - Extract Styles and Scripts from Sub Pages into the Layout
app.set("layout extractStyles", true);
//Set Up - Extract Styles and Scripts from Sub Pages into the Layout
app.set("layout extractScripts", true);
//Middleware - URL Encoder
app.use(express.urlencoded({ extended: true }));
//Middleware - App calls index.js - Route File, whenever '/' route is called in the request
app.use("/", route);
//Set Up - Template Engine as EJS
app.set("view engine", "ejs");
//Set Up - Template Engine Views Folder Path (..../views)
app.set("views", path.join(__dirname, "views"));
//Run the ExpressJS Server
app.listen(port, (err) => {
if (err) {
console.log(err);
return;
}
console.log(`Server is Up & Running Successfully on Port ${port}`);
});