-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (41 loc) · 1.33 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
//IMPORTING express framework
const express = require('express');
//MYSQL connector for NodeJS
const mysql = require('mysql');
//Importing bodyParser which is used to get HTML values(like input field result) to NodeJS
const bodyParser = require('body-parser');
//Creating Object of Express
const app = express();
//Importing Student Routes
const studentRoutes = require('./routes/Student');
//Importing Instructor/Faculty Routes
const facultyRoute = require('./routes/Instructor');
//Telling NodeJS that we will be using EJS Template Engine
app.set('view engine', 'ejs');
//this will allow EJS files to access assets folder for css files
app.use('/assets', express.static('assets'));
//Enabling bodyParser functionalities
app.use(bodyParser.urlencoded({ extended: true }));
//Creating Connection to mysql
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'college-management-system'
})
//Connecting to Mysql
db.connect((err) => {
if (err) throw err
})
//Rendering preLogger Page
app.get('/', (req, res) => {
res.render('preLogger.ejs');
})
//Student FILE accessing from here
app.use(studentRoutes);
//Instructor FILE accessing from here
app.use(facultyRoute);
//Assigning the port where we will be listening
app.listen('3000', () => {
console.log('server is listening..');
});