-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
47 lines (39 loc) · 1.25 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require("express");
//express app
const app = express();
const port = 3000;
const mongoose = require('mongoose'); //to connect to mongodb
//connect to mongodb and listen to requests
mongoose.connect("mongodb+srv://Ashita:password@cluster0.mwavz.mongodb.net/resultManagement?retryWrites=true&w=majority", {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const db = mongoose.connection;
db.on("error", (error) => console.log(error));
db.once("open", () => console.log("connected"));
//register view engine
app.set('view engine', 'ejs');
//middleware and static files
app.use(express.static('public'))
app.use(express.json());
app.use(express.urlencoded());
//express layouts
var expressLayouts = require('express-ejs-layouts');
app.use(expressLayouts);
app.set('layout', 'layouts/layout');
//teacher and student routes
const teachRoutes = require("./routes/teacherRoutes")
const studRoutes = require("./routes/studentRoutes")
app.use("/teacher",teachRoutes);
app.use("/student",studRoutes);
//routes
app.get("/", (req, res) => {
res.render("index");
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
// 404 page
app.use((req, res) => {
res.status(404).render('404', { title: '404' });
});