-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (42 loc) · 1.3 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
// Imports modules
const express = require('express')
const request = require('request');
const cron = require('node-cron');
const Chart = require('chart.js');
const app = express();
const port = 8000;
const calendar = new Date();
const path = require('path');
var bodyParser = require ('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));
// Allows access to stylesheets
app.use(express.static('public'));
// Imports MySQL
const mysql = require('mysql');
// Sets up access to the SQL Database
const db = mysql.createConnection ({
host: 'localhost',
user: 'root',
password: 'password',
database: 'stats',
multipleStatements: true
});
// Connects to database
db.connect((err) => {
if (err) {
throw err;
}
console.log('Stats Database initialised');
});
// Sets global variables
global.db = db;
global.Chart = Chart
// Sets up Express web server
require('./routes/main')(app);
app.set('views',__dirname + '/views');
app.set('view engine', 'ejs');
app.engine('html', require('ejs').renderFile);
// Schedule tasks to be run on the server.
//cron.schedule('0 0 */12 * * *', function() {});
// Message confirming Express server is running
app.listen(port, () => console.log(`Stats App running on port ${port}, started ${calendar.getDate()}/${calendar.getMonth()+1}/${calendar.getFullYear()}`))