-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (39 loc) · 1019 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
33
34
35
36
37
38
39
40
41
42
43
44
import express from "express";
import mongoose from "mongoose";
import bodyParser from "body-parser";
import dotenv from "dotenv";
import studentsRoute from "./routes/studentsRoute.js";
import { engine } from "express-handlebars";
const app = express();
app.engine(
"hbs",
engine({
extname: "hbs",
helpers: {
eq: function (a, b) {
return a === b;
},
},
})
);
app.set("view engine", "hbs");
app.set("views", "./views");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.urlencoded({ extended: true }));
dotenv.config();
const PORT = process.env.PORT || 4000;
const MONGOURL = process.env.MONGO_URL;
mongoose
.connect(MONGOURL)
.then(() => {
console.log("Database connected Successfully.");
app.listen(PORT, () => {
console.log(`Server is running on port : ${PORT}`);
});
})
.catch((error) => console.log(error));
app.get("/", (req, res) => {
res.render("home");
});
app.use("/students", studentsRoute);