-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathapp.js
52 lines (42 loc) · 1.46 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
48
49
50
51
52
/*
SETUP
*/
// Express
var express = require('express');
var app = express();
PORT = 9124;
// Database
var db = require('./database/db-connector')
/*
ROUTES
*/
app.get('/', function(req, res)
{
// Define our queries
query1 = 'DROP TABLE IF EXISTS diagnostic;';
query2 = 'CREATE TABLE diagnostic(id INT PRIMARY KEY AUTO_INCREMENT, text VARCHAR(255) NOT NULL);';
query3 = 'INSERT INTO diagnostic (text) VALUES ("MySQL is working for myONID!")'; // replace with your ONID
query4 = 'SELECT * FROM diagnostic;';
// Execute every query in an asynchronous manner, we want each query to finish before the next one starts
// DROP TABLE...
db.pool.query(query1, function (err, results, fields){
// CREATE TABLE...
db.pool.query(query2, function(err, results, fields){
// INSERT INTO...
db.pool.query(query3, function(err, results, fields){
// SELECT *...
db.pool.query(query4, function(err, results, fields){
// Send the results to the browser
let base = "<h1>MySQL Results:</h1>"
res.send(base + JSON.stringify(results));
});
});
});
});
});
/*
LISTENER
*/
app.listen(PORT, function(){
console.log('Express started on http://localhost:' + PORT + '; press Ctrl-C to terminate.')
});